Flag: Negatable
Negatable Flag with `--no-` prefix
Negatable Flag
Normal Style
A negatable flag like --warning
has a companion buddy --no-warning
.
The two flags are just the opposite.
While end user typed --no-warning
, the app.cmd.no-warning
key in the Store
will be set to true
, on the contrary, app.cmd.warning
key will be set to false
.
Internally, these two flags are in a same Toggleable Group.
A negatable Flag always holds a boolean Default value, in generally,
-W
Style
This new feature starts since cmdr v2.1.16.
A -W
-style negatable flag allows you provide a set of child items.
cmdr will create a pair of toggable group flags for these child items. For example, the above sample code will make these child flags: --warnings.unused-variable
/-Wunused-variable
and --warnings.no-unused-variable
/-Wno-unused-variable
, and so on.
This -W
-style negatable flag is covered from gcc -Waddress -Wno-address
of GNU GCC command line options.
De
.Negatable(true).Default(false)
可以为标志设置 Negatable 风格。
.Negatable(true, "a","b","c").Default(false)
可以为标志设置 -W
Style Negatable 风格。
Define
To define negatable flag by .Negatable(true).Default(false)
call.
And by .Negatable(true, "a","b","c").Default(false)
call, a -W
-style flag(-set) can be defined.
Run
The example app has these following outputs:
额外的话题
How is this guide?
Last updated on