What is the best way to have multiple options of command line arguments based on selected options. For example lets say we have sample.py
I would like to have say 3 options:
python sample.py Employee John Doe
python sample.py Address Washington Drive NY
python sample.py Number 1234567890
Was trying to add parser.add_argument('option', choices=['Employee', 'Address', 'Number'])
, so this will limit me to have the 3 options, but I guess it would be nice to have it check the required parameters as well, and maybe a detailed help -h
. Say if Employee
is chosen and only one parameter provided, it will say something like lastname
is required. If Number
is selected and provides a string, it will say something like invalid number
. Is it better to do positional arguments, or named argument, like -num 1234567890
or -firstname John -lastname Doe
. Seems positional is more simple, but can be confusing if it requires 7 parameters. How would you write the sample.py
to use argparse and handle the simple example above