From 239525bcf40db03fb75091a68ae1cdbcdc632af6 Mon Sep 17 00:00:00 2001 From: Jarryd Beck Date: Tue, 14 Oct 2014 16:59:25 +1100 Subject: [PATCH] parse into value --- src/cxxopts.hpp | 9 +++++++++ src/example.cpp | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cxxopts.hpp b/src/cxxopts.hpp index 1b100d0..ffa687a 100644 --- a/src/cxxopts.hpp +++ b/src/cxxopts.hpp @@ -194,6 +194,8 @@ namespace cxxopts void parse_value(const std::string& text, bool& value) { + //TODO recognise on, off, yes, no, enable, disable + //so that we can write --long=yes explicitly value = true; } @@ -263,6 +265,13 @@ namespace cxxopts return std::make_shared>(); } + template + std::shared_ptr + value(T& t) + { + return std::make_shared>(&t); + } + class OptionAdder; class OptionDetails diff --git a/src/example.cpp b/src/example.cpp index bce79fb..5180c86 100644 --- a/src/example.cpp +++ b/src/example.cpp @@ -30,11 +30,12 @@ int main(int argc, char* argv[]) { try { - cxxopts::Options options(argv[0]); + bool apple = false; + options.add_options() - ("a,apple", "an apple") + ("a,apple", "an apple", cxxopts::value(apple)) ("b,bob", "Bob") ("f,file", "File", cxxopts::value>()) ("positional", @@ -51,7 +52,7 @@ int main(int argc, char* argv[]) options.parse(argc, argv); - if (options.count("a")) + if (apple) { std::cout << "Saw option ‘a’" << std::endl; } -- libgit2 0.21.4