Using python's argparse module I want to pass parameters to prog two ways:
Method 1:
./filter.py filename --start_regex "^FOO" --end_regex "BAR$" --contains "XXX" --bunch_of_common_options
Method 2:
./filter.py filename --type "FOO_BAR_XXX" --bunch_of_common_options
Logically both are doing exactly the same, because there is a dict in filter.py
that translates "FOO_BAR_XXX" type from method 2 to appropriate options for method 1.
I want to specify that, given:
groupA = (--start_regex, --end_regex --contains)
groupB = (--type)
groupA and groupB are:
- mutually exclusive, and
- groupA must have at least start_regex defined
Now, I'm aware of mutually_exclusive_group functionality, but it works only on single arguments (not groups of options), and sub-commands, but it looks like I would have to have some kind of dispatch option after prog.py, like "git clone --help", or "git push --help" (this post proves that)
Note that it's not elegant to say:
./filter.py with_type filename --type TYPE1
./filter.py without_type filename --start_regex "^FOO" --end_regex "BAR$" --contains "XXX"
Or am I missing something?