parse into value

This commit is contained in:
Jarryd Beck 2014-10-14 16:59:25 +11:00
parent c8b22d113d
commit 239525bcf4
2 changed files with 13 additions and 3 deletions

View File

@ -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<values::default_value<T>>();
}
template <typename T>
std::shared_ptr<Value>
value(T& t)
{
return std::make_shared<values::default_value<T>>(&t);
}
class OptionAdder;
class OptionDetails

View File

@ -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<bool>(apple))
("b,bob", "Bob")
("f,file", "File", cxxopts::value<std::vector<std::string>>())
("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;
}