From c98fcc22659f8a0141319eefc855bca295deca22 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 11 Nov 2024 14:40:05 -0600 Subject: [PATCH] switch to table style syntax for subcommands --- src/hwylterm/hwylcli.nim | 13 ++++++++----- tests/example.nim | 10 +++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/hwylterm/hwylcli.nim b/src/hwylterm/hwylcli.nim index 4e7e1b3..95f66c2 100644 --- a/src/hwylterm/hwylcli.nim +++ b/src/hwylterm/hwylcli.nim @@ -305,18 +305,21 @@ func parseIdentLikeList(node: NimNode): seq[string] = func parseCliBody(body: NimNode, name: string = "", root: bool= false): CliCfg func isSubMarker(node: NimNode): bool = - if node.kind == nnkPrefix: - if eqIdent(node[0], "---"): - result = true + if node.kind != nnkBracket: return false + if node.len != 1: return false + if node[0].kind notin [nnkIdent, nnkStrLit]: + return false + result = true func sliceStmts(node: NimNode): seq[ tuple[name: string, slice: Slice[int]] ] = + if not isSubMarker(node[0]): error "expected a subcommand delimiting line" var - name: string = node[0][1].strVal + name: string = node[0][0].strVal start = 1 let nodeLen = node.len() @@ -325,7 +328,7 @@ func sliceStmts(node: NimNode): seq[ result.add (name, start..i) elif isSubMarker(node[i]): result.add (name, start..(i - 1)) - name = node[i][1].strVal + name = node[i][0].strVal start = i + 1 diff --git a/tests/example.nim b/tests/example.nim index 68b72b6..9bbd2ca 100644 --- a/tests/example.nim +++ b/tests/example.nim @@ -26,7 +26,7 @@ hwylCli: run: echo "this is always run prior to subcommand parsing" subcommands: - --- "onelonger" + [onelonger] ... """ the first subcommand @@ -50,7 +50,7 @@ hwylCli: echo fmt"{verbose=}" echo fmt"{config=}" - --- "two-longer" + ["two-longer"] ... """ some second subcommand @@ -58,8 +58,8 @@ hwylCli: and it will automatically be "bb"'ed [bold]this is bold text[/] """ flags: - a: - T bool + auto: + - a ? "some help" b: T seq[float] @@ -67,5 +67,5 @@ hwylCli: h "this will override the builtin 'h' for help" run: echo "hello from `example b` command" - echo fmt"{a=}, {b=}" + echo fmt"{auto=}, {b=}"