Skip to content

Commit

Permalink
Address back-handed requested missing feature to have "secret" option…
Browse files Browse the repository at this point in the history
…s via

    nim-lang/Nim#12425
Usage is the CL author saying `help={"param": "SUPPRESS"}` with the special
string being re-definable via, e.g., `clCfg.hTabSuppress = "**HIDDEN**"`.
Ammend test prog to try it out & update reference output for line numbers.
  • Loading branch information
c-blake committed Oct 22, 2019
1 parent 4f2be51 commit 0cd1c5e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions cligen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type # Main defns CLI authors need be aware of (besides top-level API calls)
reqSep*: bool ## ``parseopt3.initOptParser`` parameter
sepChars*: set[char] ## ``parseopt3.initOptParser`` parameter
opChars*: set[char] ## ``parseopt3.initOptParser`` parameter
hTabSuppress*: string ## Magic val for per-param help to suppress

HelpOnly* = object of Exception
VersionOnly* = object of Exception
Expand All @@ -40,7 +41,8 @@ var clCfg* = ClCfg(
reqSep: false,
sepChars: { '=', ':' },
opChars: { '+', '-', '*', '/', '%', '@', ',', '.', '&',
'|', '~', '^', '$', '#', '<', '>', '?' })
'|', '~', '^', '$', '#', '<', '>', '?' },
hTabSuppress: "SUPPRESS")
{.pop.}

proc toInts*(x: seq[ClHelpCol]): seq[int] =
Expand Down Expand Up @@ -405,7 +407,8 @@ macro dispatchGen*(pro: typed{nkSym}, cmdName: string="", doc: string="",
`apId`.parNm = `parNm`; `apId`.parSh = `sh`; `apId`.parReq = `isReq`
`apId`.parRend = if `hky`.len>0: `hky` else:helpCase(`parNm`,clLongOpt)
let descr = getDescription(`defVal`, `parNm`, `hlp`)
`tabId`.add(argHelp(`defVal`, `apId`) & descr)
if descr != `cf`.hTabSuppress:
`tabId`.add(argHelp(`defVal`, `apId`) & descr)
if `apId`.parReq != 0: `tabId`[^1][2] = `apId`.val4req
`cbId`.incl(optionNormalize(`parNm`), `apId`.parRend)
`allId`.add(helpCase(`parNm`, clLongOpt)))
Expand Down
6 changes: 4 additions & 2 deletions test/PerParam.nim
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
proc demo(al_pha=1, be_ta=2.0, verb=false, item="", args: seq[string]) =
proc demo(al_pha=1, be_ta=2.0, verb=false, jk=9, item="", args: seq[string]) =
## demo entry point with varied, meaningless parameters. A Nim invocation
## might be: demo(alpha=2, @[ "hi", "ho" ]) corresponding to the command
## invocation "demo --alpha=2 hi ho" (assuming executable gets named demo).
echo "alpha:", alpha, " beta:", beta, " verb:", verb, " item:", repr(item)
echo "jk: ", jk
for i, arg in args: echo "positional[", i, "]: ", repr(arg)

when isMainModule:
import cligen
dispatch(demo,
help = { "al-pha" : "growth constant",
"be-ta" : "shrink target" },
"be-ta" : "shrink target",
"jk" : "SUPPRESS" },
short = { "a-lpha" : 'z',
"b-eta" : '\0' })
6 changes: 3 additions & 3 deletions test/ref
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,9 @@ Options(opt-arg sep :|=|spc):

==> test/TwoNondefaultedSeq.out <==
test/TwoNondefaultedSeq.nim(9, 11) template/generic instantiation of `dispatch` from here
cligen.nim(688, 14) template/generic instantiation of `dispatchCf` from here
cligen.nim(674, 14) template/generic instantiation of `dispatchGen` from here
cligen.nim(186, 16) Warning: cligen only supports one seq param for positional args; using `args`, not `stuff`. Use `positional` parameter to `dispatch` to override this. [User]
cligen.nim(691, 14) template/generic instantiation of `dispatchCf` from here
cligen.nim(677, 14) template/generic instantiation of `dispatchGen` from here
cligen.nim(188, 16) Warning: cligen only supports one seq param for positional args; using `args`, not `stuff`. Use `positional` parameter to `dispatch` to override this. [User]
Usage:
demo [required&optional-params] [args: string...]
demo entry point with varied, meaningless parameters.
Expand Down

0 comments on commit 0cd1c5e

Please sign in to comment.