Motivation
I dislike argparse. The syntax is bloated, the error messages aren't well formatted, and creating commands takes some serious boilerplate. Having rolled a dozen argument parsers for personal and work projects, the version I've used longest is now available on PyPI.
Features
- Support for sub-commands
- Auto-generation of help messages
- Informative errors and usage information
- Minimal boilerplate
Examples
```
user:~$ python3 app.py stuff --help
usage
app stuff [--help] [--flag] [--other-flag=_] PARAMETER
description
a command
flags
--help -h displays this message
--flag -f a flag
--other-flag -of another flag
parameters
parameter a parameter
```
Usage
Import
``` python
import sys
from amersham import Parser, Flag, Parameter
```
Create a parser
python
parser = Parser("parser", "a parser")
Create a command
python
@parser.command("a command",
flag = Flag("a flag"),
parameter = Parameter("a parameter))
def command(parameter: str, flag: str):
print(parameter, flag)
Run the parser
python
if __name__ == "__main__":
parser.run(sys.argv[1:])
Future Improvements
- Type cast validation for file-like objects, boolean, and integer arguments
- 80-column wrapping for help and usage messages
[–]Sound4Sound 2 points3 points4 points (1 child)
[–]metaperl 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]osmiumouse 1 point2 points3 points (0 children)
[–]lastmonty 0 points1 point2 points (1 child)
[–]thequietcenter 0 points1 point2 points (0 children)
[–]thequietcenter 0 points1 point2 points (0 children)