Commit 7d4b00fa authored by Sebastian Woelke's avatar Sebastian Woelke

Allow chaining of CLI argument remainders

parent 438784fa
......@@ -239,12 +239,13 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
bool skip_remainder = false;
auto res = extract({
[&](const std::string& arg) -> optional<skip_t> {
if (skip_remainder)
return skip();
if (arg == "--") {
skip_remainder = true;
// drop frist remainder indicator
return none;
}
if (skip_remainder)
return skip();
if (arg.empty() || arg.front() != '-') {
return skip();
}
......@@ -295,7 +296,6 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
[&](const std::string& arg1,
const std::string& arg2) -> optional<skip_t> {
if (arg1 == "--") {
skip_remainder = true;
return skip();
}
if (skip_remainder)
......
......@@ -130,13 +130,25 @@ CAF_TEST(extract_opts) {
f({"-f", "hello.txt", "-l5"}, {});
f({"-fhello.txt", "-l", "5"}, {});
f({"-l5", "-fhello.txt"}, {});
// on remainder
f({"--file=hello.txt", "-l", "5", "--", "a"}, {"a"});
f({"--file=hello.txt", "-l", "5", "--", "a", "b"}, {"a", "b"});
f({"--file=hello.txt", "-l", "5", "--", "aa", "bb"}, {"aa", "bb"});
f({"--file=hello.txt", "-l", "5", "--", "-a", "--bb"}, {"-a", "--bb"});
f({"--file=hello.txt", "-l", "5", "--", "-a1", "--bb=10"},
{"-a1", "--bb=10"});
f({"--file=hello.txt", "-l", "5", "--", "-a 1", "--b=10"}, {"-a 1", "--b=10"});
f({"--file=hello.txt", "-l", "5", "--", "-a 1", "--b=10"},
{"-a 1", "--b=10"});
// multiple remainders
f({"--file=hello.txt", "-l", "5", "--", "a", "--"}, {"a", "--"});
f({"--file=hello.txt", "-l", "5", "--", "a", "--", "--"}, {"a", "--", "--"});
f({"--file=hello.txt", "-l", "5", "--", "a", "--", "b"}, {"a", "--", "b"});
f({"--file=hello.txt", "-l", "5", "--", "aa", "--", "bb"},
{"aa", "--", "bb"});
f({"--file=hello.txt", "-l", "5", "--", "aa", "--", "--", "bb"},
{"aa", "--", "--", "bb"});
f({"--file=hello.txt", "-l", "5", "--", "--", "--", "-a1", "--bb=10"},
{"--", "--", "-a1", "--bb=10"});
CAF_MESSAGE("ensure that failed parsing doesn't consume input");
auto msg = make_message("-f", "42", "-b", "1337");
auto foo = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment