diff options
author | Jarryd Beck <jarro.2783@gmail.com> | 2016-08-29 11:11:18 +0300 |
---|---|---|
committer | Jarryd Beck <jarro.2783@gmail.com> | 2016-08-29 11:11:18 +0300 |
commit | 9e3f3115d2249dc2689b39bdc51a412a23c04204 (patch) | |
tree | ade3e7619fd04d935891d1c571224d62c6549f98 /src | |
parent | b0078c65404208531c15b8dd5eb326a608f8c79b (diff) |
Don't overwrite positional arguments.
Fixes #30. The positional arguments are not overwritten when they
have already been given on the command line.
Diffstat (limited to 'src')
-rw-r--r-- | src/cxxopts.hpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/cxxopts.hpp b/src/cxxopts.hpp index 6f0dcbe..f1999d4 100644 --- a/src/cxxopts.hpp +++ b/src/cxxopts.hpp @@ -1031,20 +1031,35 @@ Options::add_to_option(const std::string& option, const std::string& arg) bool Options::consume_positional(std::string a) { - if (m_next_positional != m_positional.end()) + while (m_next_positional != m_positional.end()) { - add_to_option(*m_next_positional, a); - auto iter = m_options.find(*m_next_positional); - if (iter != m_options.end() && !iter->second->value().is_container()) { - ++m_next_positional; + if (iter != m_options.end()) + { + if (!iter->second->value().is_container()) + { + if (iter->second->count() == 0) + { + add_to_option(*m_next_positional, a); + ++m_next_positional; + return true; + } + else + { + ++m_next_positional; + continue; + } + } + else + { + add_to_option(*m_next_positional, a); + return true; + } } - return true; - } - else - { - return false; + ++m_next_positional; } + + return false; } void |