mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-11-16 06:28:32 -06:00
add subcommand aliases to help output
This commit is contained in:
parent
88572a6ce4
commit
9e35d4ea12
3 changed files with 21 additions and 5 deletions
|
@ -14,13 +14,16 @@ type
|
|||
HwylFlagHelp* = tuple
|
||||
short, long, description: string
|
||||
HwylSubCmdHelp* = tuple
|
||||
name, desc: string
|
||||
name, aliases, desc: string
|
||||
HwylCliStyleSetting = enum
|
||||
Aliases
|
||||
HwylCliStyles* = object
|
||||
header* = "bold cyan"
|
||||
flagShort* = "yellow"
|
||||
flagLong* = "magenta"
|
||||
flagDesc* = ""
|
||||
cmd* = "bold"
|
||||
settings*: set[HwylCliStyleSetting] = {Aliases}
|
||||
HwylCliHelp* = object
|
||||
usage*: string
|
||||
desc*: string
|
||||
|
@ -41,8 +44,12 @@ func newHwylCliHelp*(
|
|||
styles = HwylCliStyles()
|
||||
): HwylCliHelp =
|
||||
result.desc = dedent(desc).strip()
|
||||
result.subcmds =
|
||||
subcmds.mapIt((it.name, it.desc.firstLine))
|
||||
if Aliases in styles.settings:
|
||||
result.subcmds =
|
||||
subcmds.mapIt((it.name & " " & it.aliases, it.aliases, it.desc.firstLine))
|
||||
else:
|
||||
result.subcmds =
|
||||
subcmds.mapIt((it.name, it.aliases, it.desc.firstLine))
|
||||
result.usage = dedent(usage).strip()
|
||||
result.flags = @flags
|
||||
result.styles = styles
|
||||
|
@ -537,9 +544,10 @@ func subCmdsArray(cfg: CliCfg): NimNode =
|
|||
result = newTree(nnkBracket)
|
||||
for s in cfg.subcommands:
|
||||
let cmd = newLit(s.subName)
|
||||
let aliases = newLit(s.alias.mapIt("($1)" % [it]).join(" "))
|
||||
let desc = s.desc or newLit("")
|
||||
result.add quote do:
|
||||
(`cmd`, `desc`)
|
||||
(`cmd`, `aliases`, `desc`)
|
||||
|
||||
proc hwylCliError*(msg: string | BbString) =
|
||||
quit $(bb("error ", "red") & bb(msg))
|
||||
|
|
|
@ -46,6 +46,14 @@ hwylCli:
|
|||
? "a count flag"
|
||||
- v
|
||||
^[shared]
|
||||
subcommands:
|
||||
[subsub]
|
||||
... "another level down subcommand"
|
||||
flags:
|
||||
^color
|
||||
run:
|
||||
echo fmt"{color=}"
|
||||
|
||||
run:
|
||||
echo "hello from `example one` command!"
|
||||
echo args
|
||||
|
|
2
todo.md
2
todo.md
|
@ -20,7 +20,7 @@
|
|||
- [ ] add nargs to CliCfg
|
||||
- [x] add support for inheriting a single flag from parent (even from a "group")
|
||||
- [x] add support to either (lengthen commands) or provide an alias for a subcommand
|
||||
- [ ] add command aliases to hwylcli help with switch
|
||||
- [x] add command aliases to hwylcli help with switch
|
||||
|
||||
|
||||
## features
|
||||
|
|
Loading…
Reference in a new issue