Commit d7271eda80e19185c80418270675e02cd26f7a20

Authored by Jarryd Beck
1 parent 2fd9ab63

add vectors

src/cxxopts.hpp
... ... @@ -52,6 +52,15 @@ namespace cxxopts
52 52 }
53 53  
54 54 template <typename T>
  55 + void
  56 + parse_value(const std::string& text, std::vector<T>& value)
  57 + {
  58 + T v;
  59 + parse_value(text, v);
  60 + value.push_back(v);
  61 + }
  62 +
  63 + template <typename T>
55 64 struct value_has_arg
56 65 {
57 66 static constexpr bool value = true;
... ...
src/main.cpp
... ... @@ -36,7 +36,7 @@ int main(int argc, char* argv[])
36 36 options.add_options()
37 37 ("a,apple", "an apple")
38 38 ("b,bob", "Bob")
39   - ("f,file", "File", cxxopts::value<std::string>())
  39 + ("f,file", "File", cxxopts::value<std::vector<std::string>>())
40 40 ("positional", "Positional arguments", cxxopts::value<std::string>())
41 41 ;
42 42  
... ... @@ -56,8 +56,12 @@ int main(int argc, char* argv[])
56 56  
57 57 if (options.count("f"))
58 58 {
59   - std::cout << "File = " << options["f"].as<std::string>()
60   - << std::endl;
  59 + auto& ff = options["f"].as<std::vector<std::string>>();
  60 + std::cout << "Files" << std::endl;
  61 + for (const auto& f : ff)
  62 + {
  63 + std::cout << f << std::endl;
  64 + }
61 65 }
62 66  
63 67 if (options.count("help"))
... ...