Flag: Leading Plus Sign `+`
The leading plus sign can be recognized
+ShortFlag Flag
While an end user typing +Flag from command-line, cmdr treats it as a variation of -ShortFlag and --LongFlag.
Suppose here is a flag defined as:
b.Flg("warning", "w").
Description("negatable flag: <code>--no-warning</code> is available", "").
Group("Negatable").
LeadingPlusSign(true). // allow `+w` parsed ok
Default(false).
Build()Now both -w +w --warning are available inputs.
Once +w is been parsing, the state will be stored and its (*Flag).LeadingPlusSign() bool returns true.
So you can extract the state from the OnAction responed handler and extent it with your business logical.
OnAction(func(ctx context.Context, cmd cli.Cmd, args []string) (err error) {
wf := cmd.FlagBy("warning")
if wf != nil && wf.LeadingPlusSign() {
println("warning flag with leading plus sign: +w FOUND.")
}
return
}).
Build()Run
The possible result could be:
$ go run ./examples/leading-plus +w
warning flag with leading plus sign: +w FOUND.
$Usages
LeadingPlusSign can be recognized by cmdr and recorded, but no furture action will be launched.
Its intent depends on how you interpret it.
额外的话题
What is Next?
How is this guide?
Last updated on