How to parse sequence data and store them into std::vector #72
Replies: 3 comments
-
I'm brand new to Lyra and struggling with the same issue! I'm guessing I don't understand how to compose things properly, yet (Boost program_options does things like this for you). I've read through the docs, example code, and much of the test code and am still stumped! I'm looking for the syntax: Noticing the success handler on group(), I tried to jury-rig together something like: ...but that feels really clumsy with the extra variable and just basically wrong. I'm betting there's some neat |
Beta Was this translation helpful? Give feedback.
-
I've tried to get this to work in any number of ways yet, but no dice; it's actually forcing me to either abandon Lyra for my project, or just use a syntax I'm not that into (I'm holding out hope and going with the latter for now!). If there's a way to construct a parser for multiple alternatives, especially interleaved ("./program command --opt1 a b c --opt2 e f g --opt1 d"), I haven't hit on it yet. Even without sequence(), opt1 appears to greedily match everything. Generally, I've been trying things along the lines of this: cmd_update(lyra::cli& cli)
); Is there a gadget along the lines of: What am I missing from correct usage? (I'm posting here because I believe it's very closely related to the OP's issue.) Or is this just not supported right now? (I would even be ok with non-interleaving, e.g., "command --group-a x y z --group-b a b c" or something similar.) Help sure would be appreciated-- I'm enjoying Lyra a lot so far, and this is a head-scratcher. Thank you! |
Beta Was this translation helpful? Give feedback.
-
Unfortunately there's nothing directly available for automatically filling an
The example does use the internal string value parsing functions. But could also be done with generic standard functions or your own. Having said that.. It wouldn't be particularly difficult to add such a feature to do the splitting of the arg value(s). |
Beta Was this translation helpful? Give feedback.
-
int main(int argc, const char **argv) {
std::vector input_shape;
auto cli =
lyra::cli() |
lyra::opt(input_shape, "input-shape")["--input-shape"]("input shape");
auto result = cli.parse({argc, argv});
if (!result) {
std::cerr << "Error in command line: " << result.message() << std::endl;
return 1;
}
std::cout << std::string(69, '-') << std::endl;
std::cout << "input shape : " << input_shape << std::endl;
return 0;
}
COMMAND
$ test --input-shape 1,3,224,224
HOPE
input_shape = [1, 3, 224, 224]
thank you!
Beta Was this translation helpful? Give feedback.
All reactions