Argparse for shell scripts
Project description
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=$({
# Initialize the parser with the name of the script and a description
argparsh new $0 -d "Example parser"
# Add a positional argument - note that args after -- are options to add_arg
# and not aliases for the argument
argparsh add_arg strarg -- --help "My string argument"
# Add a keyword argument that can either be -i <value> or --intarg <value>
argparsh add_arg -i --intarg -- \
--help "My int argument" \
--type int \
--default
})
# Parse the input arguments with the parser above
eval $(argparsh parse $parser "$@")
# Access parsed arguments by name
echo "String argument was" $STRARG
echo "Integer argument was" $INTARG
See example.sh
for a more complete example.
TODO
- Subparsers
- Support for more output formats (fish, JSON, ...)
Installation
No dependencies besides python/pip.
pip install .
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
argparsh-0.0.1.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file argparsh-0.0.1.tar.gz
.
File metadata
- Download URL: argparsh-0.0.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4fc9095c9663f5eb7dc429f1af0d8963103922e2b9dd531fb7e4c6790c0325b |
|
MD5 | 5a42bb778a60efd124afccfb977aa612 |
|
BLAKE2b-256 | 9bb27a0e64d323457ef93d33eab51987e469d59c441862c88266615a546f3828 |
File details
Details for the file argparsh-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: argparsh-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ad44615a69511657ac06e4604c1dccbcb1225acab326ae0f6790d0db0d4cb72 |
|
MD5 | 19f2cfc426f49872c2b169a4b6c82b54 |
|
BLAKE2b-256 | a54074d2910d61373288616845b51a6b4f20fe70d91917335d559a53c20865cd |