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

ArgParse package: command usage ordering edge cases #3

Open
JoshuaLau0220 opened this issue Oct 20, 2023 · 0 comments
Open

ArgParse package: command usage ordering edge cases #3

JoshuaLau0220 opened this issue Oct 20, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@JoshuaLau0220
Copy link
Collaborator

Synopsis

The program produces an incorrect usage when mutually exclusive groups contain (optional) positional arguments. For example,

Parser Definition:

auto mutex1 = parser.addMutuallyExclusiveGroup();
auto mutex2 = parser.addMutuallyExclusiveGroup();

mutex2.addArgument<int>("c")
    .nargs(NArgsOption::OPTIONAL);
mutex1.addArgument<int>("a")
    .nargs(NArgsOption::OPTIONAL);

mutex1.addArgument<string>("-b");
mutex2.addArgument<string>("-d");

Usage:

Usage: Argparse [[<int a>] | -B <string B>] [[<int c>] | -D <string D>]

Description:
  ArgParse package sandbox

Positional Arguments:
  int  c     
  int  a     

Options:
  string  -B  B   
  string  -D  D

The error is that argument c should be before a, but the mutex grouping does not know how to order the groups properly. Worse still, sometimes it is just not possible to get the right order. Consider if the first group contains positional arguments 1 and 3, and the second group contains positional argument 2.

Fortunately, this should be an edge case error since it is more intuitive to define the arguments in the same groups together, thereby preventing such bad ordering from happening in the first place.

Proposed Fix

I've looked at how Python argparse handles this, and it seems like they choose to respect the positional order at the cost of breaking argument grouping. This should not be hard, but it is a bit tedious. Therefore, I've chosen to open this issue instead of trying to fix it now.

@JoshuaLau0220 JoshuaLau0220 added the bug Something isn't working label Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant