hzDocs
hzDocs
Articles / Postshedzr.comIntroduction

Guide

Your First CLI AppConcise Version
Step by step
Concepts
CommandCommand: Invoke programCommand: Presetting ArgsCommand: RedirectToCommand: DynCommandCommand: Aliases from ConfigCommand: Event HandlersFlagFlag: RequiredFlag: Toggle GroupFlag: Valid ArgsFlag: `Head -1` styleFlag: External EditorFlag: NegatableFlag: Leading Plus Sign `+`Flag: Event Handlers解析结果Builtin Commands & Flags帮助子系统Shared App辨析Package level functionsWithOptsBackstage
Howto ...
Auto-close the ClosersRead config into structUsing is DetectorsUsing Store

References

What's New
Packages

Others

Examples
Blueprint
产品发布
产品发布之前
Concepts

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.

额外的话题

Required

Toggle Group

Valid Args

Head Like

External Tool

Plus Sign

Event Handlers

What is Next?

How is this guide?

Last updated on

Flag: Negatable

Negatable Flag with `--no-` prefix

Flag: Event Handlers

OnXXX event handlers...

On this page

+ShortFlag Flag
Run
Usages
额外的话题