2014-09-27 09:04:58 +02:00
|
|
|
|
#include <codecvt>
|
2014-09-10 08:47:22 +02:00
|
|
|
|
#include <iostream>
|
2014-09-25 18:19:23 +02:00
|
|
|
|
#include <locale>
|
2014-09-27 09:04:58 +02:00
|
|
|
|
#include <sstream>
|
2014-09-10 08:47:22 +02:00
|
|
|
|
|
|
|
|
|
|
#include "cxxopts.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
std::match_results<const char*> result;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::cout << "Argument " << i << std::endl;
|
2014-09-18 07:16:51 +02:00
|
|
|
|
std::regex_match(argv[i], result, cxxopts::option_matcher);
|
2014-09-10 08:47:22 +02:00
|
|
|
|
std::cout << "empty = " << result.empty() << std::endl;
|
|
|
|
|
|
std::cout << "size = " << result.size() << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "matches:" << std::endl;
|
|
|
|
|
|
for (int j = 0; j != result.size(); ++j)
|
|
|
|
|
|
{
|
2014-09-25 18:19:23 +02:00
|
|
|
|
std::cout << "arg " << j << ": " << result[j] << std::endl;
|
2014-09-10 08:47:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-09-27 09:04:58 +02:00
|
|
|
|
cxxopts::Options options;
|
|
|
|
|
|
|
|
|
|
|
|
options.add_options()
|
|
|
|
|
|
("a,apple", "an apple")
|
|
|
|
|
|
("b,bob", "Bob")
|
2014-10-01 12:56:30 +02:00
|
|
|
|
("f,file", "File", cxxopts::value<std::string>())
|
2014-09-27 09:04:58 +02:00
|
|
|
|
;
|
|
|
|
|
|
|
2014-09-27 14:04:53 +02:00
|
|
|
|
options.parse(argc, argv);
|
|
|
|
|
|
|
2014-10-01 09:52:34 +02:00
|
|
|
|
if (options.count("a"))
|
|
|
|
|
|
{
|
|
|
|
|
|
std::cout << "Saw option ‘a’" << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (options.count("b"))
|
|
|
|
|
|
{
|
|
|
|
|
|
std::cout << "Saw option ‘b’" << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (options.count("f"))
|
|
|
|
|
|
{
|
2014-10-02 08:38:13 +02:00
|
|
|
|
std::cout << "File = " << options["f"].as<std::string>()
|
2014-10-01 12:56:30 +02:00
|
|
|
|
<< std::endl;
|
2014-10-01 09:52:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-09-10 08:47:22 +02:00
|
|
|
|
} catch (const std::regex_error& e)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::cout << "regex_error: " << e.what() << std::endl;
|
|
|
|
|
|
exit(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|