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

Subparsers of subparsers : missing parsing exception ? #261

Open
Altyrost opened this issue Mar 8, 2023 · 3 comments
Open

Subparsers of subparsers : missing parsing exception ? #261

Altyrost opened this issue Mar 8, 2023 · 3 comments

Comments

@Altyrost
Copy link

Altyrost commented Mar 8, 2023

While working with the example of subparsers in the documentation, with git:

some_exe submodule is considered valid by the parser, even if the subparser cannot have any other argument than the subparser update.

Did I miss something here ?

@skrobinson
Copy link
Contributor

If I understand correctly, you expect an error if update is missing after submodule in the parsed string.

Unless a missing argument (or subparser) is required, the parser will not report an error. Since subparsers do not have a required setting, they can never be missing.

But you can add the same logic to the git example with is_subcommand_used.

  if (program.is_subcommand_used(submodule_command) &&
      !submodule_command.is_subcommand_used(submodule_update_command)) {
    std::cout << "submodule command called without update subcommand" << std::endl;
  }

@Altyrost
Copy link
Author

Right. Shouldn't it be considered an error during the parse_arg ?

@skrobinson
Copy link
Contributor

I don't believe it is always an error. From a UI view, some authors may prefer that some_exe submodule -h shows that the update subcommand exists. An example from git is the stash command which has list, show, drop, etc. subcommands.

But, others may want to say submodule without update is an error and they can express that condition with is_subcommand_used.

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

No branches or pull requests

2 participants