Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutually exclusive groups don't appear to work #289

Open
slarse opened this issue Aug 20, 2019 · 3 comments
Open

Mutually exclusive groups don't appear to work #289

slarse opened this issue Aug 20, 2019 · 3 comments
Labels
Milestone

Comments

@slarse
Copy link

slarse commented Aug 20, 2019

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?

@Chris7
Copy link
Member

Chris7 commented Oct 28, 2019

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 Chris7 modified the milestones: v0.11.0, Future Oct 28, 2019
@slarse
Copy link
Author

slarse commented Oct 31, 2019

@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.

@CarlModeAnon
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants