mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-12-22 11:00:45 -06:00
Compare commits
No commits in common. "94e5b8708819e9a3503bee686b1617912518fccb" and "e8e090c5b76bc555231bda536193df6f92a54db2" have entirely different histories.
94e5b87088
...
e8e090c5b7
4 changed files with 31 additions and 32 deletions
|
@ -381,10 +381,11 @@ when isMainModule:
|
|||
version bbfmt"[yellow]bbansi version[/][red] ->[/] [bold]{version}[/]"
|
||||
hidden debug, testCard
|
||||
flags:
|
||||
debug "show debug"
|
||||
testCard "show test card"
|
||||
debug:
|
||||
T bool
|
||||
testCard:
|
||||
T bool
|
||||
style:
|
||||
T string
|
||||
? "set style for string"
|
||||
- "s"
|
||||
run:
|
||||
|
|
|
@ -140,9 +140,9 @@ when isMainModule:
|
|||
"""
|
||||
hidden demo
|
||||
flags:
|
||||
demo "show demo"
|
||||
demo:
|
||||
T bool
|
||||
separator:
|
||||
T string
|
||||
help "separator to split items"
|
||||
short "s"
|
||||
run:
|
||||
|
|
|
@ -61,14 +61,14 @@ func render*(cli: HwylCliHelp, f: HwylFlagHelp): string =
|
|||
if f.short != "":
|
||||
result.add "[" & cli.styles.flagShort & "]"
|
||||
result.add "-" & f.short.alignLeft(cli.shortArgLen)
|
||||
result.add "[/" & cli.styles.flagShort & "]"
|
||||
result.add "[/]"
|
||||
else:
|
||||
result.add " ".repeat(1 + cli.shortArgLen)
|
||||
result.add " "
|
||||
if f.long != "":
|
||||
result.add "[" & cli.styles.flagLong & "]"
|
||||
result.add "--" & f.long.alignLeft(cli.longArgLen)
|
||||
result.add "[/" & cli.styles.flagLong & "]"
|
||||
result.add "[/]"
|
||||
else:
|
||||
result.add " ".repeat(2 + cli.longArgLen)
|
||||
|
||||
|
@ -77,7 +77,7 @@ func render*(cli: HwylCliHelp, f: HwylFlagHelp): string =
|
|||
if f.description != "":
|
||||
result.add "[" & cli.styles.flagDesc & "]"
|
||||
result.add f.description
|
||||
result.add "[/" & cli.styles.flagDesc & "]"
|
||||
result.add "[/]"
|
||||
result.add "\n"
|
||||
|
||||
func render*(cli: HwylCliHelp, subcmd: HwylSubCmdHelp): string =
|
||||
|
@ -101,8 +101,8 @@ func render*(cli: HwylCliHelp): string =
|
|||
result.add "\n"
|
||||
result.add cli.desc
|
||||
result.add "\n"
|
||||
if cli.subcmds.len > 0:
|
||||
result.add "\n"
|
||||
if cli.subcmds.len > 0:
|
||||
result.add "[" & cli.styles.header & "]"
|
||||
result.add "subcommands[/]:\n"
|
||||
for s in cli.subcmds:
|
||||
|
@ -126,7 +126,6 @@ type
|
|||
type
|
||||
# ----
|
||||
CliSetting* = enum
|
||||
GenerateOnly, ## Don't attach root `runProc()` node
|
||||
NoHelpFlag, ## Remove the builtin help flag
|
||||
ShowHelp, ## If cmdline empty show help
|
||||
NoNormalize ## Don't normalize flags and commands
|
||||
|
@ -245,7 +244,7 @@ func parseCliFlag(n: NimNode): CliFlag =
|
|||
if result.ident == nil:
|
||||
result.ident = result.name.ident
|
||||
if result.typeNode == nil:
|
||||
result.typeNode = ident"bool"
|
||||
result.typeNode = ident"string"
|
||||
|
||||
# TODO: change how this works?
|
||||
func parseCliFlags(cfg: var CliCfg, node: NimNode) =
|
||||
|
@ -305,21 +304,18 @@ func parseIdentLikeList(node: NimNode): seq[string] =
|
|||
func parseCliBody(body: NimNode, name: string = "", root: bool= false): CliCfg
|
||||
|
||||
func isSubMarker(node: NimNode): bool =
|
||||
if node.kind != nnkBracket: return false
|
||||
if node.len != 1: return false
|
||||
if node[0].kind notin [nnkIdent, nnkStrLit]:
|
||||
return false
|
||||
if node.kind == nnkPrefix:
|
||||
if eqIdent(node[0], "---"):
|
||||
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][0].strVal
|
||||
name: string = node[0][1].strVal
|
||||
start = 1
|
||||
let nodeLen = node.len()
|
||||
|
||||
|
@ -328,7 +324,7 @@ func sliceStmts(node: NimNode): seq[
|
|||
result.add (name, start..i)
|
||||
elif isSubMarker(node[i]):
|
||||
result.add (name, start..(i - 1))
|
||||
name = node[i][0].strVal
|
||||
name = node[i][1].strVal
|
||||
start = i + 1
|
||||
|
||||
|
||||
|
@ -693,7 +689,7 @@ func hwylCliImpl(cfg: CliCfg): NimNode =
|
|||
|
||||
# should this a CritBitTree?
|
||||
parserBody.add quote do:
|
||||
var `flagSet` {.used.}: HashSet[string]
|
||||
var `flagSet`: HashSet[string]
|
||||
|
||||
parserBody.add(
|
||||
quote do:
|
||||
|
@ -783,9 +779,7 @@ func hwylCliImpl(cfg: CliCfg): NimNode =
|
|||
let `args` {.used.} = `parserProcName`(`cmdLine`)
|
||||
`runBody`
|
||||
|
||||
# if cfg.root and (GenerateOnly notin cfg.settings):
|
||||
if cfg.root:
|
||||
if GenerateOnly notin cfg.settings:
|
||||
result.add quote do:
|
||||
`runProcName`()
|
||||
else:
|
||||
|
|
|
@ -26,7 +26,7 @@ hwylCli:
|
|||
run:
|
||||
echo "this is always run prior to subcommand parsing"
|
||||
subcommands:
|
||||
[onelonger]
|
||||
--- "onelonger"
|
||||
... """
|
||||
the first subcommand
|
||||
|
||||
|
@ -50,16 +50,19 @@ hwylCli:
|
|||
echo fmt"{verbose=}"
|
||||
echo fmt"{config=}"
|
||||
|
||||
["two-longer"]
|
||||
--- "two-longer"
|
||||
... """
|
||||
some second subcommand
|
||||
|
||||
a longer mulitline description that will be visible in the subcommand help
|
||||
and it will automatically be "bb"'ed [bold]this is bold text[/]
|
||||
|
||||
|
||||
|
||||
"""
|
||||
flags:
|
||||
auto:
|
||||
- a
|
||||
a:
|
||||
T bool
|
||||
? "some help"
|
||||
b:
|
||||
T seq[float]
|
||||
|
@ -67,5 +70,6 @@ hwylCli:
|
|||
h "this will override the builtin 'h' for help"
|
||||
run:
|
||||
echo "hello from `example b` command"
|
||||
echo fmt"{auto=}, {b=}"
|
||||
echo fmt"{a=}, {b=}"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue