Replies: 2 comments 5 replies
-
Adding a subcommand named #include <CLI/CLI.hpp>
#include <iostream>
#include <string>
int main(int argc, const char *argv[]) {
int value{0};
CLI::App app{"Test App"};
app.add_option("-v", value, "value");
app.add_subcommand("++", "")->silent()->group("")->fallthrough();
std::string program1;
std::vector<std::string> args1;
auto &sub1 = *app.add_subcommand("sub1", "");
sub1.positionals_at_end();
sub1.validate_positionals();
sub1.add_flag("--foo", program1);
sub1.add_option("program", program1, "program");
sub1.add_option("args", args1, "args")->check(!CLI::IsMember({"++"}));
std::string program2;
std::vector<std::string> args2;
auto &sub2 = *app.add_subcommand("sub2", "");
sub2.positionals_at_end();
sub2.validate_positionals();
sub2.add_option("program", program2, "program");
sub2.add_option("args", args2, "args")->check(!CLI::IsMember({"++"}));
CLI11_PARSE(app, argc, argv);
std::cout << "value=" << value << '\n';
std::cout << (sub1["--foo"]->as<bool>() ? "sub1 (--foo): " : "sub1: ") << program1 << " ";
for(const auto &aarg : args1) {
std::cout << aarg << " ";
}
std::cout << '\n';
std::cout << "sub2: " << program2 << " ";
for(const auto &aarg : args2) {
std::cout << aarg << " ";
}
std::cout << '\n';
}
|
Beta Was this translation helpful? Give feedback.
3 replies
-
lets see if I understand correctly command --arg1 --arg2 value <command> <command args...> -- <command2> <command2 args...> |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
My program wraps other programs and I need to parse arbitrary name and args for the other programs. For a single command this is easy since you can just use a positional separator:
However I'm stuck trying to achieve this with subcommands. I would like to support:
However this seems to capture all of
other1 sub-conflicting --sub1-conflicting ++ sub-conflicting -- other2
in sub1's positionals.I tried adding
check(!CLI::IsMember({"++"}))
to the positional option and enablingvalidate_positionals()
on the subcommand but this gives:Beta Was this translation helpful? Give feedback.
All reactions