CLI11 icon indicating copy to clipboard operation
CLI11 copied to clipboard

Default values for options not showing (getting an error following the documentation)

Open chakizimana opened this issue 3 years ago • 5 comments

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

chakizimana avatar Nov 05 '21 19:11 chakizimana

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.

phlptp avatar Nov 05 '21 22:11 phlptp

Thank you very much for the clarification!

chakizimana avatar Nov 05 '21 23:11 chakizimana

We will leave this issue open until the docs get fixed. Thanks

phlptp avatar Nov 06 '21 12:11 phlptp

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).

HanatoK avatar Nov 19 '21 16:11 HanatoK

->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.

phlptp avatar Nov 20 '21 15:11 phlptp