summaryrefslogtreecommitdiff
path: root/src/parameters_parser.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-02-15 18:55:11 +0000
committerMaxime Coste <mawww@kakoune.org>2017-02-15 18:55:11 +0000
commit0a1cb4b9b19933f099fa89194d528911c844e2bd (patch)
treefa46c0723bab87e858b992122ab20b75c07ac0e2 /src/parameters_parser.cc
parent9e0f085b86e967d374fbe1d9f955abb325791076 (diff)
Detect when switches are specified more than once
Fixes #1219
Diffstat (limited to 'src/parameters_parser.cc')
-rw-r--r--src/parameters_parser.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/parameters_parser.cc b/src/parameters_parser.cc
index 68a497c9..30154483 100644
--- a/src/parameters_parser.cc
+++ b/src/parameters_parser.cc
@@ -19,6 +19,7 @@ ParametersParser::ParametersParser(ParameterList params,
m_desc(desc)
{
bool only_pos = desc.flags & ParameterDesc::Flags::SwitchesAsPositional;
+ Vector<bool> switch_seen(desc.switches.size(), false);
for (size_t i = 0; i < params.size(); ++i)
{
if (not only_pos and params[i] == "--")
@@ -29,6 +30,11 @@ ParametersParser::ParametersParser(ParameterList params,
if (it == m_desc.switches.end())
throw unknown_option(params[i]);
+ auto switch_index = it - m_desc.switches.begin();
+ if (switch_seen[switch_index])
+ throw runtime_error{format("switch '-{}' specified more than once", it->key)};
+ switch_seen[switch_index] = true;
+
if (it->value.takes_arg)
{
++i;