26inline namespace util {
30: description_{
std::
move(description)}
36 return opts_.count(long_opt);
41 return opts_.count(std::string_view{&short_opt, 1});
48 while (!
lex.empty()) {
49 const auto opt =
lex.
opt();
52 OptsMap::iterator
it{opts_.end()};
58 throw runtime_error{
"unexpected argument: " +
string{
lex.arg()}};
64 throw runtime_error{
"unknown option: " +
string{opt}};
71 cout << *
this <<
"\n";
79 const auto val =
lex.pop_value();
80 if (arg.set_ && !arg.multitoken_) {
81 throw runtime_error{
"duplicate option: " +
string{opt}};
85 [&](
const NoOp&) {
lex.pop(); }},
91 for (
const auto&
data : opts_) {
93 [&](
const Value& arg) {
95 throw runtime_error{
"missing required option: "
96 +
data.second->opt()};
101 for (
const auto&
data : positional_) {
103 [&](
const Value& arg) {
105 throw runtime_error{
"missing positional argument"};
114 out <<
"Usage: " <<
options.description_ <<
"\nOptions:\n";
116 for (
const auto& opt :
options.help_) {
120 if (!opt->short_opt.empty()) {
122 out <<
'-' << opt->short_opt;
124 if (!opt->long_opt.empty()) {
125 if (!opt->short_opt.empty()) {
130 out <<
"--" << opt->long_opt;
Command-line options parser.
ostream & operator<<(ostream &os, const pair< T, U > &p)