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

Custom help displays error of not given required argument #246

Open
Hind-M opened this issue Dec 2, 2022 · 1 comment
Open

Custom help displays error of not given required argument #246

Hind-M opened this issue Dec 2, 2022 · 1 comment

Comments

@Hind-M
Copy link

Hind-M commented Dec 2, 2022

For a program that has at least one required argument, using a custom help - as the following - gives an error which shouldn't be taken into account when running the help command:

program.add_argument("-h", "--help")
    .action([&](const std::string & /*unused*/)
    {
        std::cout << program.help().str();
    })
    .default_value(false)
    .help("shows help message")
    .implicit_value(true)
    .nargs(0);

The error is:

1 argument(s) expected. 0 provided.
No value provided for 'required_arg'.
@skrobinson
Copy link
Contributor

If you replace the default --help handler and have required arguments, you'll need to catch errors during parse_args and add a custom way to recover from the missing required argument.

Or don't require any arguments and check that a value was parsed and assigned to your formerly required arguments. Then you can handle the missing value with whatever feedback mechanism fits your UI.

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