Open colonelsammy opened 8 years ago
I'm considering pulling the Option
type out of Catch and making it available to Clara (and all users of Clara), so you could make your field Clara::Option<std::String> hostname;
and test it with:
if( opt.hostname ) std::cout << "Hostname was set..." << *opt.hostname << std::end;
How would that sound to you?
Yes, I think that would work pretty well...please do that!
I've achieved this by passing std::optional as the value to Opt. I implemented a trivial operator>> that simply initializes the std::optional argument with whatever T it extracts from the stream and everything works just fine. After parsing I can test if the optional value was initialized.
I've finally implemented this in Clara (not in the single include yet - but will do a release soon).
It tries to auto-detect availability of std::optional
, which seems to work for GCC, but from what I have read probably doesn't for VS 2017 yet (will get to that).
Either way you can override it to force support by defining:
CLARA_CONFIG_OPTIONAL_TYPE std::optional
Or you can use that to specify any alternative optional (template) type, as long as it supports the !
and *
operators.
I would like to know if the user specified a particular command line option. I can do that by setting a bool in a bound function, but I can't help thinking that the framework already 'knows' if the option got used...I couldn't see any way to find out if it had been set though - can it be done?
My rather cludgy example code;
This is the result that I want: