diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 190a9db..ddfdb86 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -980,6 +980,42 @@ namespace cxxopts size_t m_count = 0; }; + class KeyValue + { + public: + KeyValue(std::string key, std::string value) + : m_key(std::move(key)) + , m_value(std::move(value)) + { + } + + const + std::string& + key() const + { + return m_key; + } + + const std::string + value() const + { + return m_value; + } + + template + T + as() const + { + T result; + values::parse_value(m_value, result); + return result; + } + + private: + std::string m_key; + std::string m_value; + }; + class ParseResult { public: @@ -1018,6 +1054,12 @@ namespace cxxopts return riter->second; } + const std::vector& + arguments() const + { + return m_sequential; + } + private: OptionValue& @@ -1059,6 +1101,8 @@ namespace cxxopts std::vector::iterator m_next_positional; std::unordered_set m_positional_set; std::unordered_map, OptionValue> m_results; + + std::vector m_sequential; }; class Options @@ -1386,6 +1430,8 @@ ParseResult::parse_option { auto& result = m_results[value]; result.parse(value, arg); + + m_sequential.emplace_back(value->long_name(), arg); } inline diff --git a/test/options.cpp b/test/options.cpp index ed39a10..3533f6e 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -82,6 +82,16 @@ TEST_CASE("Basic options", "[options]") CHECK(result.count("6") == 1); CHECK(result.count("p") == 2); CHECK(result.count("space") == 2); + + auto& arguments = result.arguments(); + REQUIRE(arguments.size() == 7); + CHECK(arguments[0].key() == "long"); + CHECK(arguments[0].value() == ""); + CHECK(arguments[0].as() == true); + + CHECK(arguments[1].key() == "short"); + CHECK(arguments[2].key() == "value"); + CHECK(arguments[3].key() == "av"); } TEST_CASE("Short options", "[options]")