Getopt::Mixed::Help Perl module can combine Getopt::Mixed with usage and help.
('< filenames >...' => 'filenames to be processed',
'ENV' => 'SCRIPT_OPT_',
'ENV_' => 'SCRIPT_OPT_',
'd>debug:i number' => 'turn on debugging information (*)',
'e>execute' => 'do it without asking for confirmation',
'f>force' => 'override all safety checks',
'i>interactive' => 'asks for confirmation before doing it',
'n>no-execute' => 'just print what would be done without doing it',
'q>quiet' => 'suppress all information',
's>summary' => 'print summary information on exit',
'v>verbose:i number' => 'turn on verbose information (*)',
'(*)' => '(*) You may add a positive integer for a higher level.'
test_script -d -v 2 --summary some_file.ext other_file.ext
Getopt::Mixed::Help is a simplified interface to Getopt::Mixed adding usage (help) functionality. It automatically adds the options -?, -h and --help (the last two configurable) to print the usage text. It allows to get option values from the environment (if the operating system it runs on supports environment variables). It can also add different flavours of support for multiple options. Finally it supports debugging output of the options used.
The module uses a direct import mechanism called with a hash as parameter. The structure of the hash is as follows:
The key is a combined (SHORT > LONG [ARGUMENT SPECIFIER [VALUE IDENTIFIER]]) option description for Getopt::Mixed, except for the VALUE IDENTIFIER which is simply included into the help text. The value following the key is simply the help text for this option.
If the second character of the first key is not >, the first key is taken as descriptive identifiers for additional parameters and the help for them.
Any key starting with ( and ending with ) will be interpreted as a footnote (additional help text) to the real options. They should be used at the end of the list only.
A key equal to ENV is used to get default values for the remaining options from the environment. For any option not initialised on the command line an environment variable with the prefix of the value following ENV and a rest of the name identical to the uppercase long option name (e.g. SCRIPT_OPT_DEBUG) will be checked. If this environment variable exists, it will be used to set the option. Note that in the name of the rest of the environment variable uppercase is used and hyphens are relaced with underlines.
A key equal to ENV_ is used in the same way as the key ENV. In addition it allows for a special environment variable with the prefix of the value following ENV followed by a single underline (_) as combined initialiser (for more than one option, e.g. export SCRIPT_OPT__='debug verbose=2'). Note that no whitespaces are allowed in the values of the options initialised this way as the string in the environment variable is parsed in a simple way.
The module defines the variable $optUsage containing the complete help text.
If an option debug exists and is choosen on the command line, this module will print all option values and all remaining parameters to standard error. The name of this option may be changed, see "changing the debug option" below in the "CHANGING DEFAULT BEHAVIOUR" section.