doc: shell getopt support

Documentations has been updated acorcing to changes in the getopt
library.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
Jakub Rzeszutko 2021-07-01 11:40:14 +02:00 committed by Carles Cufí
commit 10210bd101

View file

@ -30,7 +30,7 @@ interaction is required. This module is a Unix-like shell with these features:
* Built-in handler to display help for the commands. * Built-in handler to display help for the commands.
* Support for wildcards: ``*`` and ``?``. * Support for wildcards: ``*`` and ``?``.
* Support for meta keys. * Support for meta keys.
* Support for getopt. * Support for getopt and getopt_long.
* Kconfig configuration to optimize memory usage. * Kconfig configuration to optimize memory usage.
.. note:: .. note::
@ -486,22 +486,51 @@ Getopt Feature
Some shell users apart from subcommands might need to use options as well. Some shell users apart from subcommands might need to use options as well.
the arguments string, looking for supported options. Typically, this task the arguments string, looking for supported options. Typically, this task
is accomplished by the ``getopt`` function. is accomplished by the ``getopt`` familly functions.
For this purpose shell supports the getopt library available For this purpose shell supports the getopt and getopt_long libraries available
in the FreeBSD project. I was modified so that it can be used in the FreeBSD project. This feature is activated by:
by all instances of the shell at the same time, hence its call requires :kconfig:`CONFIG_GETOPT` set to ``y`` and :kconfig:`CONFIG_GETOPT_LONG`
one more parameter. set to ``y``.
An example usage: This feature can be used in thread safe as well as non thread safe manner.
The former is full compatible with regular getopt usage while the latter
a bit differs.
An example non-thread safe usage:
.. code-block:: c .. code-block:: c
while ((char c = shell_getopt(shell, argc, argv, "abhc:")) != -1) { char *cvalue = NULL;
/* some code */ while ((char c = getopt(argc, argv, "abhc:")) != -1) {
switch (c) {
case 'c':
cvalue = optarg;
break;
default:
break;
}
} }
This module is activated by :kconfig:`CONFIG_SHELL_GETOPT` set to ``y``. An example thread safe usage:
.. code-block:: c
char *cvalue = NULL;
struct getopt_state *state;
while ((char c = getopt(argc, argv, "abhc:")) != -1) {
state = getopt_state_get();
switch (c) {
case 'c':
cvalue = state->optarg;
break;
default:
break;
}
}
Thread safe getopt functionality is activated by
:kconfig:`CONFIG_SHELL_GETOPT` set to ``y``.
Obscured Input Feature Obscured Input Feature
********************** **********************