-
Hello, I've just started using CLI11 and I have a pretty simple command line utility which does app.add_option("--dsn", opts.dsn, "The database connection string to use")
->option_text("<DSN>"); and works fine, except that if I run it with just --dsn: 1 required TEXT missing
Run with --help for more information. and the first line here seems rather awkward to me, I'd rather output something like "Required value missing for the --dsn option" or maybe "Expected --dsn option value not found". Is it possible to customize the error message in the option definition or in some other way? Looking at Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The If you wanted to fully customize it, the best way would probably be to write a callback yourself that does the check, then you can fully control the error message and all the checks. app.add_option("--dsn", [&opts](const results_t &results){
if (<some check>){
opts.dsn=results[0];
return true}
else{
throw an error with some description;
return false;
}}, "The database connection string to use")
->option_text("<DSN>")->expected(0,1); |
Beta Was this translation helpful? Give feedback.
-
The expected(0,1) is critical there. Without that the missing argument error is triggered. The |
Beta Was this translation helpful? Give feedback.
The expected(0,1) is critical there. Without that the missing argument error is triggered.
The
check(...)
won't really help since that is for validating individual arguments. Though I suppose that might work as well if you checked for a "1" or "true" with the expected(0,1).