parse into value
This commit is contained in:
parent
c8b22d113d
commit
239525bcf4
@ -194,6 +194,8 @@ namespace cxxopts
|
|||||||
void
|
void
|
||||||
parse_value(const std::string& text, bool& value)
|
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;
|
value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,6 +265,13 @@ namespace cxxopts
|
|||||||
return std::make_shared<values::default_value<T>>();
|
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 OptionAdder;
|
||||||
|
|
||||||
class OptionDetails
|
class OptionDetails
|
||||||
|
|||||||
@ -30,11 +30,12 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
cxxopts::Options options(argv[0]);
|
cxxopts::Options options(argv[0]);
|
||||||
|
|
||||||
|
bool apple = false;
|
||||||
|
|
||||||
options.add_options()
|
options.add_options()
|
||||||
("a,apple", "an apple")
|
("a,apple", "an apple", cxxopts::value<bool>(apple))
|
||||||
("b,bob", "Bob")
|
("b,bob", "Bob")
|
||||||
("f,file", "File", cxxopts::value<std::vector<std::string>>())
|
("f,file", "File", cxxopts::value<std::vector<std::string>>())
|
||||||
("positional",
|
("positional",
|
||||||
@ -51,7 +52,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
options.parse(argc, argv);
|
options.parse(argc, argv);
|
||||||
|
|
||||||
if (options.count("a"))
|
if (apple)
|
||||||
{
|
{
|
||||||
std::cout << "Saw option ‘a’" << std::endl;
|
std::cout << "Saw option ‘a’" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user