You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.
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?
c:\Projects\ClaraExample\Debug>ClaraExample.exe --host=fred
Hostname was set...fred
c:\Projects\ClaraExample\Debug>ClaraExample.exe
Hostname was NOT set...do stuff that doesn't need the hostname
The text was updated successfully, but these errors were encountered:
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;
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:
The text was updated successfully, but these errors were encountered: