forked from OctaForge/libostd
support for positional and mutually exclusive args in groups
parent
32197f600c
commit
8391b03b37
|
@ -57,6 +57,7 @@ enum class arg_value {
|
||||||
|
|
||||||
struct arg_description {
|
struct arg_description {
|
||||||
friend struct arg_description_container;
|
friend struct arg_description_container;
|
||||||
|
friend struct arg_group;
|
||||||
|
|
||||||
virtual ~arg_description() {}
|
virtual ~arg_description() {}
|
||||||
|
|
||||||
|
@ -387,8 +388,24 @@ struct arg_group: arg_description {
|
||||||
|
|
||||||
template<typename ...A>
|
template<typename ...A>
|
||||||
arg_optional &add_optional(A &&...args) {
|
arg_optional &add_optional(A &&...args) {
|
||||||
arg_optional *o = new arg_optional(std::forward<A>(args)...);
|
arg_description *p = new arg_optional(std::forward<A>(args)...);
|
||||||
return *p_opts.emplace_back(o);
|
return static_cast<arg_optional &>(*p_opts.emplace_back(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ...A>
|
||||||
|
arg_positional &add_positional(A &&...args) {
|
||||||
|
arg_description *p = new arg_positional(std::forward<A>(args)...);
|
||||||
|
return static_cast<arg_positional &>(*p_opts.emplace_back(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ...A>
|
||||||
|
arg_mutually_exclusive_group &add_mutually_exclusive_group(A &&...args) {
|
||||||
|
arg_description *p = new arg_mutually_exclusive_group(
|
||||||
|
std::forward<A>(args)...
|
||||||
|
);
|
||||||
|
return static_cast<arg_mutually_exclusive_group &>(
|
||||||
|
*p_opts.emplace_back(p)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
|
@ -415,21 +432,21 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename F>
|
template<typename F>
|
||||||
bool for_each_impl(F &func, bool) const {
|
bool for_each_impl(F &func, bool iter_ex) const {
|
||||||
for (auto &desc: p_opts) {
|
for (auto &desc: p_opts) {
|
||||||
switch (desc->type()) {
|
switch (desc->type()) {
|
||||||
case arg_type::OPTIONAL:
|
case arg_type::OPTIONAL:
|
||||||
case arg_type::POSITIONAL:
|
case arg_type::POSITIONAL:
|
||||||
if (!func(static_cast<arg_description const &>(*desc))) {
|
if (!func(*desc)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case arg_type::MUTUALLY_EXCLUSIVE_GROUP:
|
case arg_type::MUTUALLY_EXCLUSIVE_GROUP:
|
||||||
/*if (!static_cast<arg_mutually_exclusive_group const &>(
|
if (!static_cast<arg_mutually_exclusive_group const &>(
|
||||||
*desc
|
*desc
|
||||||
).for_each(func, iter_ex)) {
|
).for_each(func, iter_ex)) {
|
||||||
return false;
|
return false;
|
||||||
}*/
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* should never happen */
|
/* should never happen */
|
||||||
|
@ -440,7 +457,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string p_name;
|
std::string p_name;
|
||||||
std::vector<std::unique_ptr<arg_optional>> p_opts;
|
std::vector<std::unique_ptr<arg_description>> p_opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct arg_description_container {
|
struct arg_description_container {
|
||||||
|
|
Loading…
Reference in New Issue