feature: add `ignore` property in addition to `hidden`

you can still set the value of a hidden option,
it just dont show up in the help text.

but using `ignore`, the is no chance you can set the value from cli.
This commit is contained in:
jangko 2021-11-30 14:35:18 +07:00 committed by zah
parent 0f4961822d
commit 6a56d01381
4 changed files with 32 additions and 2 deletions

View File

@ -796,11 +796,17 @@ proc cmdInfoFromType(T: NimNode): CmdInfo =
let path = findPath(result, cmd)
for n in path:
checkDuplicate(n, opt, field.name)
cmd.opts.add opt
# the reason we check for `ignore` pragma here and not using `continue` statement
# is we do respect option hierarchy of subcommands
if field.readPragma("ignore") == nil:
cmd.opts.add opt
else:
checkDuplicate(result, opt, field.name)
result.opts.add opt
if field.readPragma("ignore") == nil:
result.opts.add opt
macro configurationRtti(RecordType: type): untyped =
let

View File

@ -53,6 +53,7 @@ template required* {.pragma.}
template command* {.pragma.}
template argument* {.pragma.}
template hidden* {.pragma.}
template ignore* {.pragma.}
template inlineConfiguration* {.pragma.}
template implicitlySelectable* {.pragma.}

View File

@ -8,6 +8,7 @@
{. warning[UnusedImport]:off .}
import
test_ignore,
test_config_file,
test_envvar

22
tests/test_ignore.nim Normal file
View File

@ -0,0 +1,22 @@
import
std/unittest,
../confutils,
../confutils/defs
type
TestConf* = object
dataDir* {.
ignore
defaultValue: "nimbus"
name: "data-dir"}: string
logLevel* {.
defaultValue: "DEBUG"
desc: "Sets the log level."
name: "log-level" }: string
suite "test ignore option":
test "ignored option have no default value":
let conf = TestConf.load()
doAssert(conf.logLevel == "DEBUG")
doAssert(conf.dataDir == "")