diff options
author | Sean Anderson <seanga2@gmail.com> | 2020-10-27 19:55:36 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-10-30 10:56:11 -0400 |
commit | 72eda5074b92d54ff67979f7a45ced9a119c4a8c (patch) | |
tree | 16758651c9b32cf51a8f1927b45be2e6af861600 /doc | |
parent | 018aad8750181590f84afc42512216946f6caeab (diff) | |
download | u-boot-72eda5074b92d54ff67979f7a45ced9a119c4a8c.tar.gz |
lib: Add getopt
Some commands can get very unweildy if they have too many positional
arguments. Adding options makes them easier to read, remember, and
understand.
This implementation of getopt has been taken from barebox, which has had
option support for quite a while. I have made a few modifications to their
version, such as the removal of opterr in favor of a separate getopt_silent
function. In addition, I have moved all global variables into struct
getopt_context.
The getopt from barebox also re-orders the arguments passed to it so that
non-options are placed last. This allows users to specify options anywhere.
For example, `ls -l foo/ -R` would be re-ordered to `ls -l -R foo/` as
getopt parsed the options. However, this feature conflicts with the const
argv in cmd_tbl->cmd. This was originally added in 54841ab50c ("Make sure
that argv[] argument pointers are not modified."). The reason stated in
that commit is that hush requires argv to stay unmodified. Has this
situation changed? Barebox also uses hush, and does not have this problem.
Perhaps we could use their fix?
I have assigned maintenance of getopt to Simon Glass, as it is currently
only used by the log command. I would also be fine maintaining it.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/getopt.rst | 8 | ||||
-rw-r--r-- | doc/api/index.rst | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/doc/api/getopt.rst b/doc/api/getopt.rst new file mode 100644 index 0000000000..773f79aeb6 --- /dev/null +++ b/doc/api/getopt.rst @@ -0,0 +1,8 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (C) 2020 Sean Anderson <seanga2@gmail.com> + +Option Parsing +============== + +.. kernel-doc:: include/getopt.h + :internal: diff --git a/doc/api/index.rst b/doc/api/index.rst index 787b6778e5..ae4a1b6c63 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -8,6 +8,7 @@ U-Boot API documentation dfu efi + getopt linker_lists pinctrl rng |