shell: make detecting help option optional
Shell will not "steal" by default "-h" and "--help" each time help functions are enabled. This change is necessary to implement and use the getopt library. Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
parent
c2afabcc7c
commit
b64fb7c92d
4 changed files with 28 additions and 3 deletions
|
@ -121,7 +121,17 @@ config SHELL_HELP
|
|||
bool "Enable help message"
|
||||
default y if !SHELL_MINIMAL
|
||||
help
|
||||
Enables formatting help message when requested with '-h' or '--help'.
|
||||
Enables shell functions for printing formatted help message.
|
||||
|
||||
config SHELL_HELP_OPT_PARSE
|
||||
bool "Parse -h and --help options"
|
||||
depends on SHELL_HELP
|
||||
depends on !SHELL_GETOPT
|
||||
default y
|
||||
help
|
||||
Shell parses command to find '-h' or '--help' string. If the shell
|
||||
finds the string, it will automatically print a help message
|
||||
for a command.
|
||||
|
||||
config SHELL_HELP_ON_WRONG_ARGUMENT_COUNT
|
||||
bool "Enable printing help on wrong argument count"
|
||||
|
|
|
@ -662,8 +662,7 @@ static int execute(const struct shell *shell)
|
|||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_SHELL_HELP) && (cmd_lvl > 0) &&
|
||||
(!strcmp(argvp[0], "-h") ||
|
||||
!strcmp(argvp[0], "--help"))) {
|
||||
z_shell_help_request(argvp[0])) {
|
||||
/* Command called with help option so it makes no sense
|
||||
* to search deeper commands.
|
||||
*/
|
||||
|
|
|
@ -187,3 +187,16 @@ void z_shell_help_cmd_print(const struct shell *shell,
|
|||
|
||||
formatted_text_print(shell, cmd->help, field_width, false);
|
||||
}
|
||||
|
||||
bool z_shell_help_request(const char *str)
|
||||
{
|
||||
if (!IS_ENABLED(CONFIG_SHELL_HELP_OPT_PARSE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!strcmp(str, "-h") || !strcmp(str, "--help")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ void z_shell_help_subcmd_print(const struct shell *shell,
|
|||
const struct shell_static_entry *cmd,
|
||||
const char *description);
|
||||
|
||||
/* Function returns true if str == -h or --help */
|
||||
bool z_shell_help_request(const char *str);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue