mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2025-02-23 09:45:50 -06:00
add check for short/long flags
This commit is contained in:
parent
06085d7ebc
commit
cbdad3454d
3 changed files with 39 additions and 5 deletions
|
@ -514,6 +514,34 @@ func pasrseCliAlias(cfg: var CliCfg, node: NimNode) =
|
||||||
cfg.alias.incl s
|
cfg.alias.incl s
|
||||||
else: bad(n, "alias")
|
else: bad(n, "alias")
|
||||||
|
|
||||||
|
func err(c: CliCfg, msg: string) =
|
||||||
|
## quit with error while generating cli
|
||||||
|
error "failed to generate " & c.name & " hwylcli: \n" & msg
|
||||||
|
|
||||||
|
func check(c: CliCfg) =
|
||||||
|
## verify the cli is valid
|
||||||
|
var
|
||||||
|
short: Table[char, CliFlag]
|
||||||
|
long: Table[string, CliFlag]
|
||||||
|
|
||||||
|
for f in c.flags:
|
||||||
|
if f.short != '\x00':
|
||||||
|
if f.short in short:
|
||||||
|
let conflict = short[f.short]
|
||||||
|
c.err "conflicting short flags for: " & f.name & " and " & conflict.name
|
||||||
|
# hwylCliImplError c, (
|
||||||
|
# "conflicting short flags for: " & f.name & " and " & conflict.name
|
||||||
|
# )
|
||||||
|
|
||||||
|
else:
|
||||||
|
short[f.short] = f
|
||||||
|
|
||||||
|
if f.long in long:
|
||||||
|
let conflict = long[f.long]
|
||||||
|
c.err "conflicting long flags for: " & f.name & " and " & conflict.name
|
||||||
|
else:
|
||||||
|
long[f.long] = f
|
||||||
|
|
||||||
func propagate(c: var CliCfg) =
|
func propagate(c: var CliCfg) =
|
||||||
for child in c.subcommands.mitems:
|
for child in c.subcommands.mitems:
|
||||||
# push the preSub to the lowest subcommand
|
# push the preSub to the lowest subcommand
|
||||||
|
@ -524,7 +552,9 @@ func propagate(c: var CliCfg) =
|
||||||
child.pre = c.preSub
|
child.pre = c.preSub
|
||||||
child.post = c.postSub
|
child.post = c.postSub
|
||||||
child.inheritFrom(c)
|
child.inheritFrom(c)
|
||||||
propagate(child)
|
propagate child
|
||||||
|
check child
|
||||||
|
|
||||||
|
|
||||||
func parseCliHelp(c: var CliCfg, node: NimNode) =
|
func parseCliHelp(c: var CliCfg, node: NimNode) =
|
||||||
## some possible DSL inputs:
|
## some possible DSL inputs:
|
||||||
|
@ -662,7 +692,11 @@ func subCmdsArray(cfg: CliCfg): NimNode =
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
(`cmd`, `aliases`, `desc`)
|
(`cmd`, `aliases`, `desc`)
|
||||||
|
|
||||||
proc hwylCliError*(msg: string | BbString) =
|
# is this one necessary?
|
||||||
|
proc hwylCliError*(msg: BbString) =
|
||||||
|
quit $(bb("error ", "red") & msg)
|
||||||
|
|
||||||
|
proc hwylCliError*(msg: string) =
|
||||||
quit $(bb("error ", "red") & bb(msg))
|
quit $(bb("error ", "red") & bb(msg))
|
||||||
|
|
||||||
func defaultUsage(cfg: CliCfg): NimNode =
|
func defaultUsage(cfg: CliCfg): NimNode =
|
||||||
|
|
2
todo.md
2
todo.md
|
@ -22,7 +22,7 @@
|
||||||
- [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
|
||||||
- [x] add command aliases to hwylcli help with switch
|
- [x] add command aliases to hwylcli help with switch
|
||||||
- [x] don't recreate "global"" variables in var section
|
- [x] don't recreate "global"" variables in var section
|
||||||
- [ ] add flag overlap check before case statement generation (use `postParse` proc)
|
- [x] add flag overlap check before case statement generation (use `postParse` proc)
|
||||||
- [x] add key-value flag support -> `--setting:a:off`
|
- [x] add key-value flag support -> `--setting:a:off`
|
||||||
- [x] add defaultFlagType CliCfg setting
|
- [x] add defaultFlagType CliCfg setting
|
||||||
- [x] add node to flagDef to override builtin `parse(p, varName)`
|
- [x] add node to flagDef to override builtin `parse(p, varName)`
|
||||||
|
|
Loading…
Add table
Reference in a new issue