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:
parent
d4559f53fa
commit
10210bd101
1 changed files with 39 additions and 10 deletions
|
@ -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.
|
||||
* Support for wildcards: ``*`` and ``?``.
|
||||
* Support for meta keys.
|
||||
* Support for getopt.
|
||||
* Support for getopt and getopt_long.
|
||||
* Kconfig configuration to optimize memory usage.
|
||||
|
||||
.. note::
|
||||
|
@ -486,22 +486,51 @@ Getopt Feature
|
|||
|
||||
Some shell users apart from subcommands might need to use options as well.
|
||||
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
|
||||
in the FreeBSD project. I was modified so that it can be used
|
||||
by all instances of the shell at the same time, hence its call requires
|
||||
one more parameter.
|
||||
For this purpose shell supports the getopt and getopt_long libraries available
|
||||
in the FreeBSD project. This feature is activated by:
|
||||
:kconfig:`CONFIG_GETOPT` set to ``y`` and :kconfig:`CONFIG_GETOPT_LONG`
|
||||
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
|
||||
|
||||
while ((char c = shell_getopt(shell, argc, argv, "abhc:")) != -1) {
|
||||
/* some code */
|
||||
char *cvalue = NULL;
|
||||
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
|
||||
**********************
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue