Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/jarro2783/cxxopts.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJarryd Beck <jarro.2783@gmail.com>2016-08-29 11:11:18 +0300
committerJarryd Beck <jarro.2783@gmail.com>2016-08-29 11:11:18 +0300
commit9e3f3115d2249dc2689b39bdc51a412a23c04204 (patch)
treeade3e7619fd04d935891d1c571224d62c6549f98 /src
parentb0078c65404208531c15b8dd5eb326a608f8c79b (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.hpp35
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