cmd: improve help for programs without subcommands
Some programs do not have subcommands (other than the standard "help",
and "version" subcommands). The cmd library provides the "noopcode"
mechanism for new subcommand-less programs, but older programs take
advantage of the optional "initcmd" token to simulate subcommand-less
programs. The "initcmd" token is optional to run the command, however
it is required to display the command help.
For example, running the xstat_cm_test program without any options gives
a syntax error:
$ xstat_cm_test
xstat_cm_test: Missing required parameter '-cmname'
...
Retrying with -help (or help, -h, --help), gives the rather unhelpful
output:
$ xstat_cm_test -help
xstat_cm_test: Commands are:
apropos search by help text
help get help on commands
initcmd initialize the program
It is not obvious to the user how to get the command usage for the
program, nor that the initcmd subcommand to "initialize the program" is
actually is a placeholder to run the program.
Instead, display the command usage when help is requested and initcmd is
the only defined subcommand for a program.
For example:
$ xstat_cm_test -help
Usage: src/xstat/xstat_cm_test [initcmd]
-cmname <Cache Manager name(s) to monitor>+
-collID <Collection(s) to fetch>+ [-onceonly]
[-frequency <poll frequency, in seconds>]
[-period <data collection time, in minutes>] [-debug] [-help]
Where: -onceonly Collect results exactly once, then quit
-debug turn on debugging output
The libcmd library now supports an "noopcode", which should used for
future subcommand-less programs, but converting old programs to remove
the initcmd opcode could break scripts which actually specify the
optional initcmd token.
This commit adds a new libcmd flag called CMD_IMPLICIT which is used to
denote built-in subcommands such as "version" and "help".
Change-Id: Iee9cb2761254543f74166e5c240685f85b6915b6
Reviewed-on: https://gerrit.openafs.org/10983
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>