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

"--help <subcommand>" runs subcommand #168

Closed
bassjoe opened this issue Sep 29, 2018 · 3 comments · Fixed by #169
Closed

"--help <subcommand>" runs subcommand #168

bassjoe opened this issue Sep 29, 2018 · 3 comments · Fixed by #169
Labels

Comments

@bassjoe
Copy link

bassjoe commented Sep 29, 2018

Would be better if either subcommand's help or a usage error is shown.

@henryiii
Copy link
Collaborator

This would be a bug. What gets run? The callback, or does it not exit the main function?

@bassjoe
Copy link
Author

bassjoe commented Sep 29, 2018

#include <iostream>
#include <CLI11.hpp>

int main(int argc, char* argv[]) {
    CLI::App cli_global {"Demo app"};
    auto& cli_sub = *cli_global.add_subcommand("sub", "Some subcommand");
    std::string sub_arg;
    cli_sub.add_option("sub_arg", sub_arg, "Argument for subcommand")->required();
    CLI11_PARSE(cli_global, argc, argv);
    if (cli_sub) {
        std::cout << sub_arg << std::endl;
    }
    return 0;
}

I just noticed that without sub_arg it shows the subcommand's help. What I'm trying to achieve is that the sub_arg is required IF the subcommand is called. Maybe I'm doing this wrong.

@henryiii
Copy link
Collaborator

I believe this is a regression. I think when the short-circuiting behavior was refactored this probably happened.

To be clear, this correctly prints help:

$ ./examples/subcom_help sub --help
  Some subcommand
  Usage: ...

And this doesn't (and should):

$ ./examples/subcom_help --help sub
  sub_arg is required
  Run with --help for more information.

henryiii added a commit that referenced this issue Sep 29, 2018
@henryiii henryiii mentioned this issue Sep 29, 2018
henryiii added a commit that referenced this issue Sep 29, 2018
@henryiii henryiii added the bug label Oct 12, 2018
henryiii added a commit that referenced this issue Oct 21, 2018
@henryiii henryiii mentioned this issue Nov 12, 2018
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants