CLI11
CLI11 copied to clipboard
Default values for options not showing (getting an error following the documentation)
My apologies if this problem has already been addressed in a different issue.
I am using the single file edition of CLI11. I have been testing out add_option()
in order to parse arguments but I am not able to output default values using the instructions in the gitbook: https://cliutils.github.io/CLI11/book/. From the documentation (this section in particular https://cliutils.github.io/CLI11/book/chapters/options.html), it is mentioned that those values are not shown by default using -h, but can be if specified by adding the optional argument true
. However, this feature does not seem to work. The only way to output those values is to use the following ->capture_default_str()
.
For instance, if I were to have a parameter called a
and be able to see their default value, this does not work:
app.add_option("-a", a, "parameter a",true);
I can only see the default value of a
if I were to do this:
app.add_option("-a", a, "parameter a")->capture_default_str()
Edit: grammar error
The boolean value at the option was removed in version 2.0. The Docs need to be updated.
The second way you are doing it is correct.
Thank you very much for the clarification!
We will leave this issue open until the docs get fixed. Thanks
I also encountered compilation error by following the current documentation. It seems capture_default_str()
can be used not only for std::string
, but also for other types (I have tried int
and it works).
->capture_default_str should be able to generate a default string for most vtypes you can use in add_option. Definitely not limited to a string output. I suppose making the function named capture_default()
might be a little clearer in that regard.