diff --git a/xfel_calibrate/calibrate.py b/xfel_calibrate/calibrate.py index 3b83c2ad6d58d832b7912c7c47c6d4d721cdd1e3..0db3e31f73e43b6d32db156088014789f2e3cabf 100755 --- a/xfel_calibrate/calibrate.py +++ b/xfel_calibrate/calibrate.py @@ -388,23 +388,18 @@ def add_args_from_nb(nb, parser, cvar=None, overwrite_reqs=False): required=required, action=make_intelli_list(ltype) if range_allowed else None) elif p.type == bool: - # check if an input arg is given with an extra "-no" for - # forcing to convert a bool to False. - # Otherwise leave the default value from the notebook - # or convert to true if the bool arg is given. - if consolize_name("--no-{}".format(p.name)) in sys.argv: - pars_group.add_argument("--{}".format(consolize_name(p.name)), - action="store_false", - default=False, - help=helpstr, - required=required) - sys.argv.remove(consolize_name("--no-{}".format(p.name))) - else: - pars_group.add_argument("--{}".format(consolize_name(p.name)), - action="store_true", - default=default, - help=helpstr, - required=required) + # For a boolean, make --XYZ and --no-XYZ options. + alt_group = pars_group.add_mutually_exclusive_group(required=required) + alt_group.add_argument("--no-{}".format(consolize_name(p.name)), + action="store_false", + default=default, + help=helpstr, + dest=p.name) + alt_group.add_argument("--{}".format(consolize_name(p.name)), + action="store_true", + default=default, + help=helpstr, + dest=p.name) else: pars_group.add_argument("--{}".format(consolize_name(p.name)), type=p.type,