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 parseCliBody(body: NimNode, name: string = "", root: bool= false): CliCfg
|
||||||
|
|
||||||
func isSubMarker(node: NimNode): bool =
|
func isSubMarker(node: NimNode): bool =
|
||||||
if node.kind == nnkPrefix:
|
if node.kind != nnkBracket: return false
|
||||||
if eqIdent(node[0], "---"):
|
if node.len != 1: return false
|
||||||
result = true
|
if node[0].kind notin [nnkIdent, nnkStrLit]:
|
||||||
|
return false
|
||||||
|
result = true
|
||||||
|
|
||||||
func sliceStmts(node: NimNode): seq[
|
func sliceStmts(node: NimNode): seq[
|
||||||
tuple[name: string, slice: Slice[int]]
|
tuple[name: string, slice: Slice[int]]
|
||||||
] =
|
] =
|
||||||
|
|
||||||
if not isSubMarker(node[0]):
|
if not isSubMarker(node[0]):
|
||||||
error "expected a subcommand delimiting line"
|
error "expected a subcommand delimiting line"
|
||||||
|
|
||||||
var
|
var
|
||||||
name: string = node[0][1].strVal
|
name: string = node[0][0].strVal
|
||||||
start = 1
|
start = 1
|
||||||
let nodeLen = node.len()
|
let nodeLen = node.len()
|
||||||
|
|
||||||
|
@ -325,7 +328,7 @@ func sliceStmts(node: NimNode): seq[
|
||||||
result.add (name, start..i)
|
result.add (name, start..i)
|
||||||
elif isSubMarker(node[i]):
|
elif isSubMarker(node[i]):
|
||||||
result.add (name, start..(i - 1))
|
result.add (name, start..(i - 1))
|
||||||
name = node[i][1].strVal
|
name = node[i][0].strVal
|
||||||
start = i + 1
|
start = i + 1
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ hwylCli:
|
||||||
run:
|
run:
|
||||||
echo "this is always run prior to subcommand parsing"
|
echo "this is always run prior to subcommand parsing"
|
||||||
subcommands:
|
subcommands:
|
||||||
--- "onelonger"
|
[onelonger]
|
||||||
... """
|
... """
|
||||||
the first subcommand
|
the first subcommand
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ hwylCli:
|
||||||
echo fmt"{verbose=}"
|
echo fmt"{verbose=}"
|
||||||
echo fmt"{config=}"
|
echo fmt"{config=}"
|
||||||
|
|
||||||
--- "two-longer"
|
["two-longer"]
|
||||||
... """
|
... """
|
||||||
some second subcommand
|
some second subcommand
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ hwylCli:
|
||||||
and it will automatically be "bb"'ed [bold]this is bold text[/]
|
and it will automatically be "bb"'ed [bold]this is bold text[/]
|
||||||
"""
|
"""
|
||||||
flags:
|
flags:
|
||||||
a:
|
auto:
|
||||||
T bool
|
- a
|
||||||
? "some help"
|
? "some help"
|
||||||
b:
|
b:
|
||||||
T seq[float]
|
T seq[float]
|
||||||
|
@ -67,5 +67,5 @@ hwylCli:
|
||||||
h "this will override the builtin 'h' for help"
|
h "this will override the builtin 'h' for help"
|
||||||
run:
|
run:
|
||||||
echo "hello from `example b` command"
|
echo "hello from `example b` command"
|
||||||
echo fmt"{a=}, {b=}"
|
echo fmt"{auto=}, {b=}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue