Command
What is Subcommand
Sample app
Without subcmd - Covered on wget
Just like grep, awk or more classical Unix apps, they are not using subcommand to keep simple and small.
But things goes complicated over time, this is a certainly truth.
So you will see lots of flags in wget app. Some of these flags has command's behavior in fact.
Anyway, here is a non-completely covered app for wget, written with cmdr way:
There is an OnAction handler attached to app object, which will handle the app call from command-line without subcmds (but flags).
With CommandBuilder/FlagBuilder way, you can setup it by RootBuilder:
It's similar with app.Cmd("subcmd").With(func(b cli.CommandBuilder){ ... }). Here parent means app.RootCommand() object, and b is for the new creating subcmd.
The app runs as:

With subcmd
See it at lots-of-subcommands.
Colorful fields
Before Description was been displaying, it will be formatted by color Translator in is/term/color.
So it's colorful.
The translating microcodes includes a tiny html tag expander. That is saying, these following codes works well:
The corresponding output on a colorful terminal simulator would be:

For more details please see readme of hedzr/is.
Except for Description field, This features also works for these fields: Header, Footer and Examples, and so on.
Expanding envvar at displaying
At displaying time, for instace help screen printing, the environment variables will be expanded for those large text fields:
Description (single line or multiple lines), Examples, Note, and so on.
The behavior includes two actions:
- The
$AppNametext will be expanded byos.ExpandEnv(), - The
{ {.AppNmae}}text will be expanded by atext.Templateengine.
In the first form, which variables could be expanded, were decided by your shell. Besides these, cmdr also injects some extra variables into the running env. It includes,
You could get an exact list of them by running app ~~debug ~~env.
In the second form, the variables are specified by a struct definition:
To see its source code, go and surf func (s *parseCtx) Translate(pattern string) (result string).
额外的话题
How is this guide?
Last updated on