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 not working in sub-command example #23

Closed
Morwenn opened this issue Apr 27, 2020 · 4 comments
Closed

Help not working in sub-command example #23

Morwenn opened this issue Apr 27, 2020 · 4 comments

Comments

@Morwenn
Copy link

Morwenn commented Apr 27, 2020

I was trying to get lyra::help to work with the add_argument interface and the sub-command example has just that. However, it looks like --help is not working in this case. I got it to work by moving the cli.parse invocation before the check for show_help - I believe that it's the right fix (parsing the command line for --help before checking the corresponding flag makes sense to me) but it's my first time trying Lyra so I can't really be sure.

I believe that it was introduced when implementing the fix for #16.

@grafikrobot
Copy link
Member

Can you post what commands you tried and what you expected?

@Morwenn
Copy link
Author

Morwenn commented May 5, 2020

I tried that nugget of code from the documentation:

/* [insert definitions of run_command and kill_command here] */

int main(int argc, const char** argv)
{
    auto cli = lyra::cli_parser();
    std::string command;
    bool show_help = false;
    cli.add_argument(lyra::help(show_help));
    cli.add_argument(lyra::arg(command, "command") 
                         .choices(run_command::name(), kill_command::name())
                         .required()
                         .help("Command to perform."));
    if (show_help)
    {
        std::cout << cli;
        return 0;
    }
    auto result = cli.parse({ argc, argv });
    /* ... */
}

Then I tried to call the resulting program with --help and it didn't work: I had to put the cli.parse() line above the check for show_help to make it work properly.

I know that this specific example is not really about showing how to use lyra::help with the add_argument interface, but it's the only example in the documentation which does so, so I just copied that part and expected it to work.

@grafikrobot
Copy link
Member

Sorry it took a bit.. But it looks like this is a duplicate error report. It was fixed some time ago: 5657ff1

Thanks for reporting the problem and for using the library.

@Morwenn
Copy link
Author

Morwenn commented May 15, 2020

Indeed, I apparently missed that one. Thanks for maintaining the library :)

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