Embed verification logic in applicator::apply.
This commit is contained in:
parent
e6d0b30f37
commit
d094fdfab0
@ -31,6 +31,7 @@ void ApplyAction(Obj &O, const Action & action, const Actions & ... actions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
// Option
|
||||||
|
|
||||||
struct Opt : public cxxopts::Option
|
struct Opt : public cxxopts::Option
|
||||||
{
|
{
|
||||||
@ -49,6 +50,9 @@ struct Opt : public cxxopts::Option
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
// Parser
|
||||||
|
|
||||||
struct Parser : public cxxopts::Options
|
struct Parser : public cxxopts::Options
|
||||||
{
|
{
|
||||||
template <typename ... Actions>
|
template <typename ... Actions>
|
||||||
@ -66,12 +70,28 @@ struct Parser : public cxxopts::Options
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
// Exception
|
||||||
|
|
||||||
|
class option_multiset_error : public cxxopts::OptionSpecException
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit option_multiset_error(const std::string& option)
|
||||||
|
: OptionSpecException("Option " +
|
||||||
|
cxxopts::LQUOTE + option + cxxopts::RQUOTE +
|
||||||
|
" is set multiple times.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace yaco /// Applicators - the instance properties implicit modifier.
|
namespace yaco /// Applicators - the instance properties implicit modifier.
|
||||||
{
|
{
|
||||||
template <unsigned N> struct applicator <char[N]>
|
|
||||||
{
|
template <unsigned N> struct applicator <char[N]>
|
||||||
|
{
|
||||||
static void apply(const char *str, Parser &Os)
|
static void apply(const char *str, Parser &Os)
|
||||||
{
|
{
|
||||||
Os.program_name(std::string(str));
|
Os.program_name(std::string(str));
|
||||||
@ -79,9 +99,14 @@ namespace yaco /// Applicators - the instance properties implicit modifier.
|
|||||||
|
|
||||||
static void apply(const char *str, Opt &O)
|
static void apply(const char *str, Opt &O)
|
||||||
{
|
{
|
||||||
|
if (!O.opts_.empty())
|
||||||
|
{
|
||||||
|
cxxopts::throw_or_mimic<option_multiset_error>
|
||||||
|
(std::string(str) + " (previous: " + O.opts_ + ")");
|
||||||
|
}
|
||||||
O.opts_ = std::string(str);
|
O.opts_ = std::string(str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} /// yaco
|
} /// yaco
|
||||||
|
|
||||||
namespace yaco /// The instance properties explicit modifier.
|
namespace yaco /// The instance properties explicit modifier.
|
||||||
@ -117,7 +142,7 @@ namespace yaco /// The instance properties explicit modifier.
|
|||||||
|
|
||||||
yaco::Parser options("objectification-demo");
|
yaco::Parser options("objectification-demo");
|
||||||
yaco::Opt help("h,help", yaco::desc("display help messages."), yaco::inject(options));
|
yaco::Opt help("h,help", yaco::desc("display help messages."), yaco::inject(options));
|
||||||
yaco::Opt job("j,job", "jobs", yaco::type<int>(), yaco::inject(options));
|
yaco::Opt job("j", yaco::desc("jobs"), yaco::type<int>(), yaco::inject(options));
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
auto result = options.parse(argc, argv);
|
auto result = options.parse(argc, argv);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user