mirror of https://github.com/jarro2783/cxxopts.git
Merge bb377507a1 into b6135315a5
This commit is contained in:
commit
e1b01aac48
|
|
@ -402,6 +402,9 @@ class Value : public std::enable_shared_from_this<Value>
|
|||
virtual bool
|
||||
is_container() const = 0;
|
||||
|
||||
virtual bool
|
||||
is_multitoken() const = 0;
|
||||
|
||||
virtual bool
|
||||
has_implicit() const = 0;
|
||||
|
||||
|
|
@ -414,6 +417,9 @@ class Value : public std::enable_shared_from_this<Value>
|
|||
virtual std::string
|
||||
get_implicit_value() const = 0;
|
||||
|
||||
virtual std::shared_ptr<Value>
|
||||
multitoken() = 0;
|
||||
|
||||
virtual std::shared_ptr<Value>
|
||||
default_value(const std::string& value) = 0;
|
||||
|
||||
|
|
@ -1322,6 +1328,12 @@ class abstract_value : public Value
|
|||
return type_is_container<T>::value;
|
||||
}
|
||||
|
||||
bool
|
||||
is_multitoken() const override
|
||||
{
|
||||
return m_multitoken;
|
||||
}
|
||||
|
||||
void
|
||||
parse() const override
|
||||
{
|
||||
|
|
@ -1346,6 +1358,13 @@ class abstract_value : public Value
|
|||
return m_implicit && (m_implicit_arg_policy == ImplicitArgPolicy::Disabled);
|
||||
}
|
||||
|
||||
std::shared_ptr<Value>
|
||||
multitoken() override
|
||||
{
|
||||
m_multitoken = true;
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
std::shared_ptr<Value>
|
||||
default_value(const std::string& value) override
|
||||
{
|
||||
|
|
@ -1404,6 +1423,7 @@ class abstract_value : public Value
|
|||
|
||||
bool m_default = false;
|
||||
bool m_implicit = false;
|
||||
bool m_multitoken = false;
|
||||
|
||||
// NOTE: Only meaningful when m_implicit == true
|
||||
ImplicitArgPolicy m_implicit_arg_policy = ImplicitArgPolicy::Enabled;
|
||||
|
|
@ -2717,6 +2737,8 @@ OptionParser::parse(int argc, const char* const* argv)
|
|||
int current = 1;
|
||||
bool consume_remaining = false;
|
||||
auto next_positional = m_positional.begin();
|
||||
std::shared_ptr<OptionDetails> current_multitoken = nullptr;
|
||||
std::string current_multitoken_name;
|
||||
|
||||
std::vector<std::string> unmatched;
|
||||
|
||||
|
|
@ -2743,9 +2765,13 @@ OptionParser::parse(int argc, const char* const* argv)
|
|||
}
|
||||
}
|
||||
|
||||
if (current_multitoken != nullptr)
|
||||
{
|
||||
parse_option(current_multitoken, current_multitoken_name, argv[current]);
|
||||
}
|
||||
//if true is returned here then it was consumed, otherwise it is
|
||||
//ignored
|
||||
if (consume_positional(argv[current], next_positional))
|
||||
else if (consume_positional(argv[current], next_positional))
|
||||
{
|
||||
}
|
||||
else
|
||||
|
|
@ -2760,6 +2786,7 @@ OptionParser::parse(int argc, const char* const* argv)
|
|||
if (argu_desc.grouping)
|
||||
{
|
||||
const std::string& s = argu_desc.arg_name;
|
||||
current_multitoken = nullptr;
|
||||
|
||||
for (std::size_t i = 0; i != s.size(); ++i)
|
||||
{
|
||||
|
|
@ -2778,6 +2805,11 @@ OptionParser::parse(int argc, const char* const* argv)
|
|||
}
|
||||
|
||||
auto value = iter->second;
|
||||
if (value->value().is_multitoken())
|
||||
{
|
||||
current_multitoken = value;
|
||||
current_multitoken_name = name;
|
||||
}
|
||||
|
||||
if (i + 1 == s.size())
|
||||
{
|
||||
|
|
@ -2812,6 +2844,7 @@ OptionParser::parse(int argc, const char* const* argv)
|
|||
else if (argu_desc.arg_name.length() != 0)
|
||||
{
|
||||
const std::string& name = argu_desc.arg_name;
|
||||
current_multitoken = nullptr;
|
||||
|
||||
auto iter = m_options.find(name);
|
||||
|
||||
|
|
@ -2829,6 +2862,11 @@ OptionParser::parse(int argc, const char* const* argv)
|
|||
}
|
||||
|
||||
auto opt = iter->second;
|
||||
if (opt->value().is_multitoken())
|
||||
{
|
||||
current_multitoken = opt;
|
||||
current_multitoken_name = name;
|
||||
}
|
||||
|
||||
//equals provided for long option?
|
||||
if (argu_desc.set_value)
|
||||
|
|
|
|||
Loading…
Reference in New Issue