argparse
argparse copied to clipboard
Custom `help` displays error of not given required argument
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'.
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.