fix cli test and whitespace

This commit is contained in:
Daylin Morgan 2024-11-14 12:01:56 -06:00
parent 1412ad8309
commit 3de786f003
Signed by: daylin
GPG key ID: 950D13E9719334AD
2 changed files with 15 additions and 10 deletions

View file

@ -44,6 +44,8 @@ func newHwylCliHelp*(
flags: openArray[HwylFlagHelp] = @[], flags: openArray[HwylFlagHelp] = @[],
styles = HwylCliStyles() styles = HwylCliStyles()
): HwylCliHelp = ): HwylCliHelp =
result.header = dedent(header).strip()
result.footer = dedent(footer).strip()
result.description = dedent(description).strip() result.description = dedent(description).strip()
if Aliases in styles.settings: if Aliases in styles.settings:
result.subcmds = result.subcmds =
@ -102,29 +104,28 @@ func render*(cli: HwylCliHelp, subcmd: HwylSubCmdHelp): string =
func render*(cli: HwylCliHelp): string = func render*(cli: HwylCliHelp): string =
if cli.header != "": if cli.header != "":
result.add cli.header result.add cli.header
result.add "\n"
if cli.usage != "": if cli.usage != "":
result.add "\n\n"
result.add "[" & cli.styles.header & "]" result.add "[" & cli.styles.header & "]"
result.add "usage[/]:\n" result.add "usage[/]:\n"
result.add indent(cli.usage, 2 ) result.add indent(cli.usage, 2 )
result.add "\n"
if cli.description != "": if cli.description != "":
result.add "\n" result.add "\n\n"
result.add cli.description result.add cli.description
result.add "\n"
if cli.subcmds.len > 0: if cli.subcmds.len > 0:
result.add "\n" result.add "\n\n"
result.add "[" & cli.styles.header & "]" result.add "[" & cli.styles.header & "]"
result.add "subcommands[/]:\n" result.add "subcommands[/]:\n"
for s in cli.subcmds: for s in cli.subcmds:
result.add cli.render(s) result.add cli.render(s)
if cli.flags.len > 0: if cli.flags.len > 0:
result.add "\n" result.add "\n\n"
result.add "[" & cli.styles.header & "]" result.add "[" & cli.styles.header & "]"
result.add "flags[/]:\n" result.add "flags[/]:\n"
for f in cli.flags: for f in cli.flags:
result.add render(cli,f) result.add render(cli,f)
if cli.footer != "": if cli.footer != "":
result.add "\n"
result.add cli.footer result.add cli.footer
proc bb*(cli: HwylCliHelp): BbString = proc bb*(cli: HwylCliHelp): BbString =
@ -655,7 +656,7 @@ func generateCliHelpProc(cfg: CliCfg, printHelpName: NimNode): NimNode =
helpFlags = cfg.flagsArray() helpFlags = cfg.flagsArray()
subcmds = cfg.subCmdsArray() subcmds = cfg.subCmdsArray()
styles = cfg.help.styles or (quote do: HwylCliStyles()) styles = cfg.help.styles or (quote do: HwylCliStyles())
<<< usage
result = quote do: result = quote do:
proc `printHelpName`() = proc `printHelpName`() =
echo bb(render(newHwylCliHelp( echo bb(render(newHwylCliHelp(

View file

@ -3,7 +3,7 @@ import std/[
] ]
import hwylterm, hwylterm/cli import hwylterm, hwylterm/hwylcli
suite "cli": suite "cli":
test "cli": test "cli":
@ -13,5 +13,9 @@ suite "cli":
[yellow]-h[/] [magenta]--help [/] []show this help[/] [yellow]-h[/] [magenta]--help [/] []show this help[/]
[yellow]-V[/] [magenta]--version[/] []print version[/] [yellow]-V[/] [magenta]--version[/] []print version[/]
""" """
let cli = newHwylCli("[b]test-program[/] [[args...]",flags = [("h","help","show this help",),("V","version","print version")]) let cli =
check $cli == $bb(expected) newHwylCliHelp(
header = "[b]test-program[/] [[args...]",
flags = [("h","help","show this help",),("V","version","print version")]
)
check $bb(cli) == $bb(expected)