shell: add getopt library support

This functionality is is enabled by setting CONFIG_SHELL_GETOPT.
It is not active by default.

User can call following functions inside command handlers:
 - shell_getopt - getopt function based on freebsd implementation
 - shell_getopt_status_get - returns getopt status

Beware when getopt functionality is enabled shell will not parse
command handler to look for "-h" or "--help" options and print
help message automatically.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
Jakub Rzeszutko 2021-01-15 14:04:21 +01:00 committed by Anas Nashif
commit 7e46765153
6 changed files with 124 additions and 1 deletions

View file

@ -533,6 +533,10 @@ static int exec_cmd(const struct shell *shell, size_t argc, const char **argv,
}
if (!ret_val) {
#if CONFIG_SHELL_GETOPT
z_shell_getopt_init(&shell->ctx->getopt_state);
#endif
z_flag_cmd_ctx_set(shell, true);
/* Unlock thread mutex in case command would like to borrow
* shell context to other thread to avoid mutex deadlock.