Setting up Python's ArgumentParser with two mutually excluding flags where one flag has optional additional flags -
i define following using python's argumentparser:
--mutually_exclusive_flag_a stringparameter --mutually_exclusive_flag_b stringparameter --optional_b_flag_one --optional_b_flag_two
one can use either mutually_exclusive_flag_a or mutually_exclusive_flag_b, not both.
if 1 uses mutually_exclusive_flag_b, 1 can use optional_b_flag_one , optional_b_flag_two.
optional_b_flag_one , optional_b_flag_two boolean flags.
i see add_mutally_exclusive_group handle selecting mutually_exclusive_flag_a or mutually_exclusive_flag_b. however, not sure how declare if use mutually_exclusive_flag_b, optional_b_flag_one , optional_b_flag_two valid flags.
it seems may able use subparsers feature , turn mutually_exclusive_flag_a , mutually_exclusive_flag_b commands.
what best option?
argparse
can't handle complex of test. mutually exclusive groups can't nested, , don't handle other kinds of logic (only xor
, not and
, or
). i've explored such expansion in python bug/issue, it's not trivial addition.
the best choice own testing after parsing.
the primary purpose of argparse
figure out user wants. checking validity, , issuing nice error message plus, not central parsing task.
one of problems expanding mechanism write meaningful usage message general combinations. have thought how you'd explain requirement users?
Comments
Post a Comment