From c5f70cec4e40ba396f59162e98c359a1a1ea4fe1 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 18 Nov 2024 14:52:43 -0600 Subject: [PATCH] fix positional handling --- src/hwylterm/hwylcli.nim | 18 +++++++++--------- tests/example.nim | 5 ++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/hwylterm/hwylcli.nim b/src/hwylterm/hwylcli.nim index 8d67359..622933d 100644 --- a/src/hwylterm/hwylcli.nim +++ b/src/hwylterm/hwylcli.nim @@ -856,8 +856,8 @@ func setFlagVars(cfg: CliCfg): NimNode = else: cfg.flags.filterIt(it.group != "global") result.add flags.mapIt( - nnkIdentDefs.newTree(it.ident, it.typeNode, newEmptyNode()) - ) + nnkIdentDefs.newTree(it.ident, it.typeNode, newEmptyNode()) + ) func literalFlags(f: CliFlag): NimNode = var flags: seq[string] @@ -932,13 +932,13 @@ func parseArgs[T](p: OptParser, target: var seq[T]) = func argOfBranch(cfg: CliCfg): NimNode = result = nnkOfBranch.newTree(ident"cmdArgument") - if cfg.args.len == 0 and cfg.subcommands.len == 0: - result.add quote do: - hwylCliError("unexpected positional argument: [b]" & p.key) - else: - result.add quote do: - inc nArgs - parseArgs(p, result) + # if cfg.args.len == 0 and cfg.subcommands.len == 0: + # result.add quote do: + # hwylCliError("unexpected positional argument: [b]" & p.key) + # else: + result.add quote do: + inc nArgs + parseArgs(p, result) func hwylCliImpl(cfg: CliCfg): NimNode = diff --git a/tests/example.nim b/tests/example.nim index f317e9c..766c137 100644 --- a/tests/example.nim +++ b/tests/example.nim @@ -78,7 +78,10 @@ hwylCli: T seq[float] ? "multiple floats" h "this will override the builtin 'h' for help" + def: + ? "a flag with a string default" + * "the value" run: echo "hello from `example b` command" - echo fmt"{thing=}, {b=}" + echo fmt"{thing=}, {b=}, {h=}, {def=}"