I am looking for a way to parse the following commandline syntax using the argparse module in python3:
myapp.py [folder] [[from] to]
Meaning: The user may optionally define a folder, which defaults to cwd. Additionally the user may pass up to two integers. If only one number is given, it should be stored in the to variable. This is similar to the syntax of the python builtin range().
e.g.:
myapp.py folder
myapp.py 10
myapp.py 5 10
myapp.py folder 5 10
myapp.py folder 10
Is that possible? If so, how?
I’d also suggest parsing sys.argv yourself.
FWIW, I parse sys.argv even on projects where argparse or similar would work, because parsing sys.argv yourself plays nicely with pylint or flake8.