Commit 239525bcf40db03fb75091a68ae1cdbcdc632af6

Authored by Jarryd Beck
1 parent c8b22d11

parse into value

src/cxxopts.hpp
... ... @@ -194,6 +194,8 @@ namespace cxxopts
194 194 void
195 195 parse_value(const std::string& text, bool& value)
196 196 {
  197 + //TODO recognise on, off, yes, no, enable, disable
  198 + //so that we can write --long=yes explicitly
197 199 value = true;
198 200 }
199 201  
... ... @@ -263,6 +265,13 @@ namespace cxxopts
263 265 return std::make_shared<values::default_value<T>>();
264 266 }
265 267  
  268 + template <typename T>
  269 + std::shared_ptr<Value>
  270 + value(T& t)
  271 + {
  272 + return std::make_shared<values::default_value<T>>(&t);
  273 + }
  274 +
266 275 class OptionAdder;
267 276  
268 277 class OptionDetails
... ...
src/example.cpp
... ... @@ -30,11 +30,12 @@ int main(int argc, char* argv[])
30 30 {
31 31 try
32 32 {
33   -
34 33 cxxopts::Options options(argv[0]);
35 34  
  35 + bool apple = false;
  36 +
36 37 options.add_options()
37   - ("a,apple", "an apple")
  38 + ("a,apple", "an apple", cxxopts::value<bool>(apple))
38 39 ("b,bob", "Bob")
39 40 ("f,file", "File", cxxopts::value<std::vector<std::string>>())
40 41 ("positional",
... ... @@ -51,7 +52,7 @@ int main(int argc, char* argv[])
51 52  
52 53 options.parse(argc, argv);
53 54  
54   - if (options.count("a"))
  55 + if (apple)
55 56 {
56 57 std::cout << "Saw option ‘a’" << std::endl;
57 58 }
... ...