mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-12-21 10:40:44 -06:00
fix cli test and whitespace
This commit is contained in:
parent
1412ad8309
commit
3de786f003
2 changed files with 15 additions and 10 deletions
|
@ -44,6 +44,8 @@ func newHwylCliHelp*(
|
|||
flags: openArray[HwylFlagHelp] = @[],
|
||||
styles = HwylCliStyles()
|
||||
): HwylCliHelp =
|
||||
result.header = dedent(header).strip()
|
||||
result.footer = dedent(footer).strip()
|
||||
result.description = dedent(description).strip()
|
||||
if Aliases in styles.settings:
|
||||
result.subcmds =
|
||||
|
@ -102,29 +104,28 @@ func render*(cli: HwylCliHelp, subcmd: HwylSubCmdHelp): string =
|
|||
func render*(cli: HwylCliHelp): string =
|
||||
if cli.header != "":
|
||||
result.add cli.header
|
||||
result.add "\n"
|
||||
if cli.usage != "":
|
||||
result.add "\n\n"
|
||||
result.add "[" & cli.styles.header & "]"
|
||||
result.add "usage[/]:\n"
|
||||
result.add indent(cli.usage, 2 )
|
||||
result.add "\n"
|
||||
if cli.description != "":
|
||||
result.add "\n"
|
||||
result.add "\n\n"
|
||||
result.add cli.description
|
||||
result.add "\n"
|
||||
if cli.subcmds.len > 0:
|
||||
result.add "\n"
|
||||
result.add "\n\n"
|
||||
result.add "[" & cli.styles.header & "]"
|
||||
result.add "subcommands[/]:\n"
|
||||
for s in cli.subcmds:
|
||||
result.add cli.render(s)
|
||||
if cli.flags.len > 0:
|
||||
result.add "\n"
|
||||
result.add "\n\n"
|
||||
result.add "[" & cli.styles.header & "]"
|
||||
result.add "flags[/]:\n"
|
||||
for f in cli.flags:
|
||||
result.add render(cli,f)
|
||||
if cli.footer != "":
|
||||
result.add "\n"
|
||||
result.add cli.footer
|
||||
|
||||
proc bb*(cli: HwylCliHelp): BbString =
|
||||
|
@ -655,7 +656,7 @@ func generateCliHelpProc(cfg: CliCfg, printHelpName: NimNode): NimNode =
|
|||
helpFlags = cfg.flagsArray()
|
||||
subcmds = cfg.subCmdsArray()
|
||||
styles = cfg.help.styles or (quote do: HwylCliStyles())
|
||||
<<< usage
|
||||
|
||||
result = quote do:
|
||||
proc `printHelpName`() =
|
||||
echo bb(render(newHwylCliHelp(
|
||||
|
|
|
@ -3,7 +3,7 @@ import std/[
|
|||
]
|
||||
|
||||
|
||||
import hwylterm, hwylterm/cli
|
||||
import hwylterm, hwylterm/hwylcli
|
||||
|
||||
suite "cli":
|
||||
test "cli":
|
||||
|
@ -13,5 +13,9 @@ suite "cli":
|
|||
[yellow]-h[/] [magenta]--help [/] []show this help[/]
|
||||
[yellow]-V[/] [magenta]--version[/] []print version[/]
|
||||
"""
|
||||
let cli = newHwylCli("[b]test-program[/] [[args...]",flags = [("h","help","show this help",),("V","version","print version")])
|
||||
check $cli == $bb(expected)
|
||||
let cli =
|
||||
newHwylCliHelp(
|
||||
header = "[b]test-program[/] [[args...]",
|
||||
flags = [("h","help","show this help",),("V","version","print version")]
|
||||
)
|
||||
check $bb(cli) == $bb(expected)
|
||||
|
|
Loading…
Reference in a new issue