if (programName_.empty()) {
programName_ = guessProgramName();
}
- auto parsed = parseNestedCommandLine(args, globalOptions_);
+
+ bool not_clean = false;
+ std::vector<std::string> cleanArgs;
+ std::vector<std::string> endArgs;
+
+ for (auto& na : args) {
+ if (na == "--") {
+ not_clean = true;
+ } else if (not_clean) {
+ endArgs.push_back(na);
+ } else {
+ cleanArgs.push_back(na);
+ }
+ }
+
+ auto parsed = parseNestedCommandLine(cleanArgs, globalOptions_);
po::variables_map vm;
po::store(parsed.options, vm);
if (vm.count("help")) {
auto cmdOptions =
po::command_line_parser(parsed.rest).options(info.options).run();
+
po::store(cmdOptions, vm);
po::notify(vm);
auto cmdArgs = po::collect_unrecognized(cmdOptions.options,
po::include_positional);
+ cmdArgs.insert(cmdArgs.end(), endArgs.begin(), endArgs.end());
+
if (initFunction_) {
initFunction_(cmd, vm, cmdArgs);
}
callHelper({"--help"});
callHelper({"--help", "foo"});
callHelper({"--help", "bar"});
+ callHelper({"--help", "--", "bar"});
callHelper({"help"});
callHelper({"help", "foo"});
callHelper({"help", "bar"});
// wrong command name
callHelper({"--help", "qux"}, 1);
callHelper({"help", "qux"}, 1);
+
+ // anything after -- is parsed as arguments
+ callHelper({"--", "help", "bar"}, 1);
}
TEST(ProgramOptionsTest, DevFull) {
callHelper({"--help"}, 1, full.fd());
}
+TEST(ProgramOptionsTest, CutArguments) {
+ // anything after -- is parsed as arguments
+ EXPECT_EQ(
+ "running foo\n"
+ "foo global-foo 43\n"
+ "foo local-foo 42\n"
+ "foo arg b\n"
+ "foo arg --local-foo\n"
+ "foo arg 44\n"
+ "foo arg a\n",
+ callHelper(
+ {"foo", "--global-foo", "43", "--", "b", "--local-foo", "44", "a"}));
+}
+
TEST(ProgramOptionsTest, Success) {
EXPECT_EQ(
"running foo\n"