mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-11-16 06:28:32 -06:00
switch to table style syntax for subcommands
This commit is contained in:
parent
0c55d85bda
commit
c98fcc2265
2 changed files with 13 additions and 10 deletions
|
@ -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], "---"):
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -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=}"
|
||||
|
||||
|
|
Loading…
Reference in a new issue