summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;