[Refactoring] Use Typer instead of argparse?
How to use optional command line arguments in a python function? - Stack Overflow
python - Parse known and unknown args with typer cli - Stack Overflow
[Feat]: Use Typer instead of Argparse
Anyone have recommendations on using Click or Typer for my first CLI tool? Click looks good and claims to solve some problems of argpase and typer. I am leaning towards using it but wanted to see how people view using that as opposed to just argpase. I hope it will be a good project with collaborators so I want to start the project off with something that works well and has good base for other collaborators.
Argparse should do this. It is feature rich and flexible. For your case, the below does the job:
import argparse
parser = argparse.ArgumentParser(description='Description of your app here.')
parser.add_argument('-N', '--integers', default=5, help='your help text here')
parser.add_argument('-S', '--sortby', default='Change', choices=['Change', 'SomeOtherOption'], help='some help text here ')
if __name__ == "__main__":
args = parser.parse_args()
print(args.integers) # prints 5 if nothing provided
print(args.sortby) # prints 'Change' if nothing provided
You can try with argparse or Typer
argparse: https://docs.python.org/3/library/argparse.html
typer: https://typer.tiangolo.com/
I've grown tired of the literal strictness of argparse and these endless cli parameter names.
Is there a plug-in substitution that would simplify the cognitive load required to build something significant in python using the cli? Something that would prompt the cli user with possible answers or pick correct files
Just today I ran into something that I would never imagine argparse doing.$ cloc ../test/data/*.csv -l
Option l is ambiguous (lang-no-ext, lang_no_ext, list-file, list_file)