Wooey
Wooey copied to clipboard
Mutually exclusive groups don't appear to work
A parser with a mutually exclusive argument group behaves pretty strangely. I've noted two problems:
- The arguments always end up as optional, even if the group is marked as required.
- This is really the larger issue for me
- You can enter input for both and don't get an error until the script actually runs
Here's a small script recreating both issues:
import argparse
import sys
parser = argparse.ArgumentParser(
description="Parser with required mutually exclusive group."
)
parser.add_argument("--arg", type=str, required=True)
mutex_grp = parser.add_mutually_exclusive_group(required=True)
mutex_grp.add_argument("--first", action="store_true")
mutex_grp.add_argument("--second", action="store_true")
def main():
args = parser.parse_args()
print(args)
return 0
if __name__ == "__main__":
sys.exit(main())
I think Gooey has support for mutex groups, so maybe inspiration can be taken from there?
For a UI, what sort of things make sense for mutually exclusive groups? I've seen some examples online of people using radio buttons to select which element they wish to fill out, but I'd prefer to not force another click.
@Chris7 Sorry for the late reply, and huge thanks for looking into the issues that I posted.
Good question, and take my thoughts here with a grain of salt as I'm not a front end developer, nor a common end-user.
Radio buttons is also what I've seen used, I guess it's either that or a drop-down, but with the latter I'm not quite sure how you'd smoothly handle the case where the mutually exclusive selections are of different type. For example:
mutex_grp = parser.add_mutually_exclusive_group(required=True)
mutex_grp.add_argument("--first", action="store_true")
mutex_grp.add_argument("--second", type="str")
I can't come up with a better solution than just rendering the different inputs "normally" inside of a bounding box, and having a radio button next to each. It's transparent in that it lets the user see all of the available options and what can be entered into them.
It's also important that, if the group is not required, that there is a possibility of selecting no option.
A parser with a mutually exclusive argument group behaves pretty strangely. I've noted two problems:
- The arguments always end up as optional, even if the group is marked as required.
- This is really the larger issue for me
- You can enter input for both and don't get an error until the script actually runs
Here's a small script recreating both issues:
import argparse import sys parser = argparse.ArgumentParser( description="Parser with required mutually exclusive group." ) parser.add_argument("--arg", type=str, required=True) mutex_grp = parser.add_mutually_exclusive_group(required=True) mutex_grp.add_argument("--first", action="store_true") mutex_grp.add_argument("--second", action="store_true") def main(): args = parser.parse_args() print(args) return 0 if __name__ == "__main__": sys.exit(main())
I think Gooey has support for mutex groups, so maybe inspiration can be taken from there?