diff --git a/include/popl.hpp b/include/popl.hpp index 8fd668b..e473099 100644 --- a/include/popl.hpp +++ b/include/popl.hpp @@ -339,7 +339,8 @@ class OptionParser /// Parse the command line into the added Options /// @param argc command line argument count /// @param argv command line arguments - void parse(int argc, const char* const argv[]); + /// @param start_index index of starting argument + void parse(int argc, const char * const argv[], int start_index = 1); /// Delete all parsed options void reset(); @@ -993,9 +994,9 @@ inline void OptionParser::parse(const std::string& ini_filename) } } -inline void OptionParser::parse(int argc, const char* const argv[]) +inline void OptionParser::parse(int argc, const char* const argv[], int start_index) { - for (int n = 1; n < argc; ++n) + for (int n = start_index; n < argc; ++n) { const std::string arg(argv[n]); if (arg == "--") diff --git a/test/test_main.cpp b/test/test_main.cpp index 63ae619..2364c55 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -54,3 +54,17 @@ TEST_CASE("config file") } } +TEST_CASE("start index") +{ + OptionParser op("Allowed options"); + auto help_option = op.add("h", "help", "produce help message"); + auto int_option = op.add>("i", "int", "test for int value", 42); + std::vector args = {"popl", "-h", "--", "-i", "43"}; + + op.parse(args.size(), args.data(), 3); + REQUIRE(help_option->count() == 0); + REQUIRE(int_option->is_set()); + REQUIRE(int_option->count() == 1); + REQUIRE(int_option->value() == 43); +} +