Builtin Commands & Flags
provided by cmdr
The builtin commands and flags
Up to cmdr v2.1.x, we provides these following builtin commands and flags.
Some of them are not planned to be implemented right away.
Our misson is staying to freeze the core APIs currently. This work has almost been done in v2.1.
Commands
generatemanualdoc(NOT-YET)shell
sbomversionhelp
help Command
help Command is very like --help flag, but it worked under a prompt mode, so you can query any commands with their help screen again and again, and launch one of them.
We planned to make a Q&A subsystem here, and it's partial done now.
version Command
version Command lists the version number and built information mainly.
In your build script, following Production is appreciated. It will include: write the building metadata into the target executable file, and other relevant data. Then the version command's output will be meaningful.
See also --version.
The verbose level is varies in the two forms above.
NOTE that app version or app versions command is equivalent to app --version.
sbom Command
This command will print Golang SBOM information with YAML format.
So user can integrated it into their ERM or Supplier Chain Management system.
generate Command
The gen command is used for generating Linux manual and shell autocompletion script mainly.
generate doc (NOT-YET)
For cmdr.v1, this command can be used to generate markdown pages.
But in cmdr v2, it's not implemented yet. No further plan.
generate man
This command can walk the command tree and build the corresponding manpages.
For example, it generates ./man1/app-jump-to.man for the command jump to. For the app's root command, it generates ./man1/app.man for you.
All of the manpages should be deployed to the man/man1/app/ on your target OS. For those GNU-like, Linux-like, or Unix-like systems, this means a directory specified by MANPAGE environment variable. To ensure whatever folder should be exact target directory, you could run manpath shell command to get the information:
Or, another way is,
By default, app generate man will make a new directory ./man1 and write all manpages in it. A sample result looks like:
For the end-user, they can read help screen in manpage mode inplace:
--man tells cmdr transfer the help screen with manpage format and pipe it into man command.
See also:
- Linux 命令 man 全知全会 (in Chinese Only)
generate shell
cmdr.v2 and v1 ships the generators of shell autocompletion scripts now (since v2.1.11).
Generally you can always deploy the autocompletion script file automatically, especially for zsh environment:
But in another shells, it's necessary to move the generated autocompletion script file to the proper location manually.
app generate shell will try detecting these shells, and complete the most of tasks for you:
- zsh
- bash
- fish
- elvish (NOT YET)
- fig-shell (NOT YET)
- powershell
In theory, the autocompletion feature for your app will be enabled as well. But the well-tests are still needed for those shells such as fish-shell, powershell and so on.
A sample of auto-completing flag of a subcommand was drawn in the following screenshot:

Another sample is for auto-completing a subcommand:

Flags
--help: print help screen--man: print help screen with manpage style--version: print versions information--build-info: print built information--version-sim: set a temporary version to expose to container system (such as k8s)--strict-mode: STRICT Mode & level--no-color: No Color Mode & Level--quiet: Quiet Mode & Level--verbose: Verbose Mode & Level--debug: Debug Mode & Level--config=FILEspecify a main config file for loading, overpassing the internal searching logics~~tree: print all commands (and flags) in tree mode~~debug: print internal debugging information
A notable thing is, --man will write a man.1 file for the current command, and launch the man.1 into man system.
Details
--version-sim
--version-sim can be used to simulate a temporary version different with the solidified one at building, which will be reported to the container mananger such as k8s.
Sometimes the feature might be useful for the gray scale test, A/B test and so on.
Modes and Levels
There are four modes for running an app: STRICT, NO-COLOR, QUIET and VERBOSE.
They are extracted and defined at is.Env() inside package hedzr/is.
Refer these topics for the details:
is.VerboseModeEnabled(),is.GetVerboseLevel()is.QuietModeEnabled(),is.GetQuietLevel()is.NoColorModeEnabled(),is.GetNoColorLevel()is.DebugMode(),is.GetDebugLevel()is.TraceMode(),is.GetTraceLevel()
--tree
~~tree and ~~tree -vvv was introduced earlier, which two forms will show the commands (and flags) hierarchical tree for you.
--debug
~~debug ~~env ... can be used to print the internal structures for a debugging purpose, specially including the k-v entries of Option Store.
FORCE_DEFAULT_ACTION envvar
FORCE_DEFAULT_ACTION=1 can enable using the internal default action handler instead of yours. The default action handler will print the hit-info for debugging.
FORCE_DEFAULT_ACTION is a temporary way to replace your handlers, even if in Production release.
In development time, you can call to the default action handler programmatically, by passing cmdr.Opt to app.Run(opts...) with cmdr.WithForceDefaultAction(true). A sample fragment is:
FORCE_RUN=1 has the opposite purpose, it would be used for overpassing the cmdr.WithForceDefaultAction(true).
Inside your OnAction(cb) handler, you can call into the default action by:
version
version flag is equavalent to version command, to show the versions information.
In your build script, following Production is appreciated. It will include: write the building metadata into the target executable file, and other relevant data. Then the version command's output will be meaningful.
See also version command.
A possible output of app --version is:
build-info
--build-info/--built-info prints the built information.
In your build script, following Production is appreciated. It will include: write the building metadata into the target executable file, and other relevant data. Then the version command's output will be meaningful.
The output looks like this:
Tree
The ~~tree flag has the leading double tilde characters ~~.
The optional -vvv can enable a verbose mode, in which the flags, the vendor-hidden items will be shown in list.
This flag can print the commands (and flags) with hierarchical tree mode.
Learn More
How is this guide?
Last updated on