-
Roland Mas authoredRoland Mas authored
bash-argsparse
An high level argument parsing library for bash.
Inspired, by the python argparse module, bash-argsparse purpose is to replace the option-parsing and usage-describing functions commonly rewritten in all scripts.
This library is implemented for GNU bash version >= 4.2. Prior versions of bash will fail at interpreting that code.
Online documentation
Doxygen documentation is available online here.
Tarballs
Though Bash Argsparse is hosted at github, you can download tarballs at the following URL: http://argsparse.livna.org/
RPMS
Though you can build your own package using the provided spec file, a bash-argsparse package is currently available in fedora repositories, for all releases from fedora 19 to rawhide. Ditto for RHEL/Centos 6 & 7, through the EPEL repository.
Features
The argsparse library offers to script developpers the following features:
- Automatic help message generation
- Simple option declarations
- Different option types: simple, with value, with cumulative (uniq or not) values
- User-input checkings (either by type, enumerations or custom checking)
- Hook settings
- Option properties making them excluding each other, aliasing other options, or (sic) non-optional.
- Automatic bash completion generation.
Requirements, Bash settings
A basic argsparse run requires no external commands except the quite-common "getopt" command. Some argsparse-built-in type checkings may require some other (like "host" and "getent") but you do not have to use those types.
Argsparse relies on a lot of bash built-in commands ("printf", "[", "read", ...) and internal features such as arrays, associative arrays, extended (ksh-like) globbing. That's why the "extglob" shell option is automatically enabled and posix-mode is automatically disabled when loading the argsparse library.
The code has been tested on bash 4.1, 4.2 and 4.3 and is definitely not POSIX-compliant.
Compliance with the "nounset" and "failglob" bash settings is supported.
Content
- argsparse.sh: the library.
- tutorial: a bunch of small demonstration scripts for new users.
- bash-argsparse.spec: a spec file to build RPM packages.
- debian: the directory required to build deb packages.
- Doxyfile: doxygen configuration file.
- doxygen-bash.sed: bash-doxygen doxygen input filter.
- unittest: a test script to validate most of argsparse features.