Print usage help if parse failed #737
-
If the parse fails, I get a message like this:
How can I have it print the usage string, too, instead of requiring another run with
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
the definition of CLI11_PARSE is #ifndef CLI11_PARSE
#define CLI11_PARSE(app, argc, argv) \
try { \
(app).parse((argc), (argv)); \
} catch(const CLI::ParseError &e) { \
return (app).exit(e); \
}
#endif If you wanted the help to print on an error what you would probably want on your parsing instead of using the MACRO is try {
app.parse(argc, argv);
} catch(const CLI::ParseError &e) {
auto retval=app.exit(e);
if (retval!= static_cast<int>(ExitCodes::Success)
{
out<< app.help();
}
} |
Beta Was this translation helpful? Give feedback.
-
Another Probably better option is
or you could define your custom callback function to go into the failure_message callback to do whatever you wanted to do. |
Beta Was this translation helpful? Give feedback.
Another Probably better option is
or you could define your custom callback function to go into the failure_message callback to do whatever you wanted to do.