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
|
HwylFlagHelp* = tuple
|
||||||
short, long, description: string
|
short, long, description: string
|
||||||
HwylSubCmdHelp* = tuple
|
HwylSubCmdHelp* = tuple
|
||||||
name, desc: string
|
name, aliases, desc: string
|
||||||
|
HwylCliStyleSetting = enum
|
||||||
|
Aliases
|
||||||
HwylCliStyles* = object
|
HwylCliStyles* = object
|
||||||
header* = "bold cyan"
|
header* = "bold cyan"
|
||||||
flagShort* = "yellow"
|
flagShort* = "yellow"
|
||||||
flagLong* = "magenta"
|
flagLong* = "magenta"
|
||||||
flagDesc* = ""
|
flagDesc* = ""
|
||||||
cmd* = "bold"
|
cmd* = "bold"
|
||||||
|
settings*: set[HwylCliStyleSetting] = {Aliases}
|
||||||
HwylCliHelp* = object
|
HwylCliHelp* = object
|
||||||
usage*: string
|
usage*: string
|
||||||
desc*: string
|
desc*: string
|
||||||
|
@ -41,8 +44,12 @@ func newHwylCliHelp*(
|
||||||
styles = HwylCliStyles()
|
styles = HwylCliStyles()
|
||||||
): HwylCliHelp =
|
): HwylCliHelp =
|
||||||
result.desc = dedent(desc).strip()
|
result.desc = dedent(desc).strip()
|
||||||
result.subcmds =
|
if Aliases in styles.settings:
|
||||||
subcmds.mapIt((it.name, it.desc.firstLine))
|
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.usage = dedent(usage).strip()
|
||||||
result.flags = @flags
|
result.flags = @flags
|
||||||
result.styles = styles
|
result.styles = styles
|
||||||
|
@ -537,9 +544,10 @@ func subCmdsArray(cfg: CliCfg): NimNode =
|
||||||
result = newTree(nnkBracket)
|
result = newTree(nnkBracket)
|
||||||
for s in cfg.subcommands:
|
for s in cfg.subcommands:
|
||||||
let cmd = newLit(s.subName)
|
let cmd = newLit(s.subName)
|
||||||
|
let aliases = newLit(s.alias.mapIt("($1)" % [it]).join(" "))
|
||||||
let desc = s.desc or newLit("")
|
let desc = s.desc or newLit("")
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
(`cmd`, `desc`)
|
(`cmd`, `aliases`, `desc`)
|
||||||
|
|
||||||
proc hwylCliError*(msg: string | BbString) =
|
proc hwylCliError*(msg: string | BbString) =
|
||||||
quit $(bb("error ", "red") & bb(msg))
|
quit $(bb("error ", "red") & bb(msg))
|
||||||
|
|
|
@ -46,6 +46,14 @@ hwylCli:
|
||||||
? "a count flag"
|
? "a count flag"
|
||||||
- v
|
- v
|
||||||
^[shared]
|
^[shared]
|
||||||
|
subcommands:
|
||||||
|
[subsub]
|
||||||
|
... "another level down subcommand"
|
||||||
|
flags:
|
||||||
|
^color
|
||||||
|
run:
|
||||||
|
echo fmt"{color=}"
|
||||||
|
|
||||||
run:
|
run:
|
||||||
echo "hello from `example one` command!"
|
echo "hello from `example one` command!"
|
||||||
echo args
|
echo args
|
||||||
|
|
2
todo.md
2
todo.md
|
@ -20,7 +20,7 @@
|
||||||
- [ ] add nargs to CliCfg
|
- [ ] add nargs to CliCfg
|
||||||
- [x] add support for inheriting a single flag from parent (even from a "group")
|
- [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
|
- [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
|
## features
|
||||||
|
|
Loading…
Reference in a new issue