From 3de786f003d4e92866b0a31ca5c9bd5e1e0cf280 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 14 Nov 2024 12:01:56 -0600 Subject: [PATCH] fix cli test and whitespace --- src/hwylterm/hwylcli.nim | 15 ++++++++------- tests/tcli.nim | 10 +++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/hwylterm/hwylcli.nim b/src/hwylterm/hwylcli.nim index c24c09c..6c2633d 100644 --- a/src/hwylterm/hwylcli.nim +++ b/src/hwylterm/hwylcli.nim @@ -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( diff --git a/tests/tcli.nim b/tests/tcli.nim index c90201e..34f6e44 100644 --- a/tests/tcli.nim +++ b/tests/tcli.nim @@ -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)