When using the actions module we should add “standard” subcommands to access the automatic script generation. We can do it by plugging in the following actions declarations:
mbfl_declare_action_set HELP
mbfl_declare_action HELP HELP_USAGE NONE \
usage \
'Print the help screen and exit.'
mbfl_declare_action HELP HELP_PRINT_COMPLETIONS_SCRIPT NONE \
print-completions-script \
'Print the completions script for this program.'
mbfl_declare_action_set MAIN
mbfl_declare_action MAIN HELP HELP \
help \
'Help the user of this script.'
and add the following action functions:
declare -r COMPLETIONS_SCRIPT_NAMESPACE='p-mbfl-examples'
function script_before_parsing_options_HELP () {
script_USAGE="usage: ${script_PROGNAME} help [action] [options]"
script_DESCRIPTION='Help the user of this program.'
}
function script_action_HELP () {
# By faking the selection of the MAIN action: we cause "mbfl_main_print_usage_screen_brief" to
# print the main usage screen.
mbfl_actions_fake_action_set MAIN
mbfl_main_print_usage_screen_brief
}
function script_before_parsing_options_HELP_USAGE () {
script_USAGE="usage: ${script_PROGNAME} help usage [options]"
script_DESCRIPTION='Print the usage screen and exit.'
}
function script_action_HELP_USAGE () {
if mbfl_wrong_num_args 0 $ARGC
then
# By faking the selection of the MAIN action: we cause "mbfl_main_print_usage_screen_brief"
# to print the main usage screen.
mbfl_actions_fake_action_set MAIN
mbfl_main_print_usage_screen_brief
else
mbfl_main_print_usage_screen_brief
exit_because_wrong_num_args
fi
}
function script_before_parsing_options_HELP_PRINT_COMPLETIONS_SCRIPT () {
script_PRINT_COMPLETIONS="usage: ${script_PROGNAME} help print-completions-script [options]"
script_DESCRIPTION='Print the command-line completions script and exit.'
}
function script_action_HELP_PRINT_COMPLETIONS_SCRIPT () {
if mbfl_wrong_num_args 0 $ARGC
then mbfl_actions_completion_print_script "$COMPLETIONS_SCRIPT_NAMESPACE" "$script_PROGNAME"
else
mbfl_main_print_usage_screen_brief
exit_because_wrong_num_args
fi
}
This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.