clipp
clipp copied to clipboard
Support std::optional<..>
I would like to be able to parse a struct containing std::optional<..>
fields. For example:
struct arg_values {
std::optional<int> pid;
} values;
auto cli = (
clipp::option("--pid") & clipp::opt_integer("PID", values.parent_pid)
);
Good idea. I should definitly add built-in support for std::optional
.
One thing this would provide is a straight forward way to check if an optional argument was passed or not.
Is there currently a canonical way to do that? I guess I could use .call(...)
with some lambda that sets a bool to true, but that seems quite verbose. I was thinking something like:
option("--foo").set_true(foo_passed) & value(foo)
Or a way to get a handle the "option object" and query it after command line parsing, something like foo_option.was_passed()
.
Is there currently a canonical way to do that?
To answer my own question, according to https://github.com/muellan/clipp#actions I guess you can do:
bool foo_passed = false;
int foo = 0;
option("--foo").set(foo_passed) & value("FOO", foo);