argparsh - python argparse for the shell
Ever wanted to parse arguments in bash but felt frustrated by giant case blocks
and unfriendly syntax? Ever tried getopts but ended up curled on the floor
sobbing? Have you ever spent sleepless nights hoping that bash argument parsing
could be as simple as python's argparse? Maybe argparsh is for you.
argparsh aims to provide an easy way to construct an argument parsing program
from any shell.
Usage
# Create a parser that accepts a string and an optional int value
parser=
# Parse the input arguments with the parser above
# Access parsed arguments by name
See examples/example.sh for a complete example, and examples of alternate
output formats (e.g. parsing CLI arguments into an associative array). The
examples directory has a few other examples that show different ways to use
argparsh in general.
Installation
Or, to build from source:
Similar Works
argparsh differs from previous attempts at improving shell argument parsing by being shell agnostic (although only bash is tested, it is relatively easy to add support for more shells, contributions are welcome), supporting subcommands/subparsers, and allowing detailed + customizable help text to be configured.
- getopts
- the OG argument handling utility. A bit clunky to use.
- argparse.sh
- similar approach, but not completely shell agnostic, and lacking in more advanced features, like subcommands.
- fish argparse
- Fish specific, but a nice utility. Not easy to use outside of fish and no subcommand support.