[scripts] proposal to switch to GNU getopt to parse command line options or improve options handling otherwise
Command line options handing in shell scripts lack the well defined and same time feature rich standard solution. Usually there are following options considered:
-
Custom code -- currently used approach but lacks pair of features listed below.
-
Using shell built-in
getopts
. At least in recent version of POSIX standards it's defined. However it lacks support of long options. -
Using standalone BSD
getopt
binary. It has some drawbacks and generally considered legacy. I'm not sure it's available in modern Linux distro repositories. -
Using standalone GNU
getopt
binary. It handles all the features listed below. It's available inutil-linux
package in modern distros. It's considered to be non-portable solution for non-Linux systems. However it's probably not an issue for the project bound to Linux technologies.
Features I would like to use:
-
Optionally use space instead of equal sign to delimit option and it's argument. I.e. option
--ostree-files=/path/to/ostree/files
to be also correctly handled as--ostree-files /path/to/ostree/file
. In case of using spaces default bash completion works nicely suggesting variants for pathes. But completion don't work with equal sign by default. -
Ability to merge short options. So instead of
-c -n
one could use-cn
.
More details:
https://en.wikipedia.org/wiki/Getopts
https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash