Skip to content

Commit

Permalink
Fix(cli): Allow space between option and value
Browse files Browse the repository at this point in the history
The help message made it seem that the syntax for specifying an option
with a value is like:
  `--verbosity quiet`
  `--verbosity q`
  `-o quiet`
  `-o q`

But the only supported syntax was actually:
  `--verbosity=quiet`
  `--verbosity=q`
  `-o=quiet`
  `-o=q`

(Or a colon instead of an equals sign).

With this commit, both of the above syntaxes work.
  • Loading branch information
ee7 committed Oct 9, 2020
1 parent 413d805 commit 83e0036
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/cli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const
("v", "version"),
]

optsNoVal = {optCheck, optHelp, optVersion}

func short(opt: Opt): string =
result = optKeys[opt].short

Expand Down Expand Up @@ -110,7 +112,13 @@ proc initConf: Conf =
proc processCmdLine*: Conf =
result = initConf()

for kind, key, val in getopt():
var shortNoVal: set[char]
var longNoVal = newSeqOfCap[string](optsNoVal.len)
for opt in optsNoVal:
shortNoVal.incl(opt.short[0])
longNoVal.add(opt.long)

for kind, key, val in getopt(shortNoVal = shortNoVal, longNoVal = longNoVal):
case kind
of cmdLongOption, cmdShortOption:
case key
Expand Down

0 comments on commit 83e0036

Please sign in to comment.