0

I know that it can be solved by if - else statement, my question is about native argparse support for this issue.

Let's say my script have two flags:

--nocreate and --rehydrate

--rehydrate flag is only valid if --nocreate flag exists

So

my_script.py --nocreate - valid

my_script.py --nocreate --rehydrate - valid

my_script.py --rehydrate - error, missing --nocreate flag

Thanks

Samuel
  • 3,631
  • 5
  • 37
  • 71
  • The accepted answer in the 'duplicate' link is exactly what you propose - an `if` test after parsing. You could implement that action in a custom Action class, but it requires the same logic. Have you thought about what the `usage` should look like? How would you instruct your users? – hpaulj May 16 '16 at 19:13
  • If `rehydrate` can't be used without `nocreate`, why not define a new flag `--norehydrate` that means `nocreate and rehydrate`? Ultimately the goal of `argparse` is to figure out what your user wants, not to tell them how to jump through the right hoops. – hpaulj May 17 '16 at 01:01

0 Answers0