Skip to content

Commit

Permalink
Remove unused code in Argument::validate
Browse files Browse the repository at this point in the history
As far as I can tell, this statement is never true.

When m_values.size() < *expected, ::consume has already thrown "Too few
arguments..." before ::validate is called.

When m_values.size() > *expected, ArgumentParser::parse_args_internal
has already thrown "Maximum number of positional arguments exceeded"
before ::validate is called.

If ::remaining is used to avoid the last exception, this Argument will
always consume the expected number of values, hence this expression is
again false.

Signed-off-by: Sean Robinson <[email protected]>
  • Loading branch information
skrobinson committed Apr 27, 2022
1 parent b9dd1ef commit 37a1f3b
Showing 1 changed file with 0 additions and 7 deletions.
7 changes: 0 additions & 7 deletions include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,6 @@ class Argument {
void validate() const {
if (auto expected = maybe_nargs()) {
if (m_is_optional) {
if (m_is_used && m_values.size() != *expected && !m_is_repeatable &&
!m_default_value.has_value()) {
std::stringstream stream;
stream << m_used_name << ": expected " << *expected
<< " argument(s). " << m_values.size() << " provided.";
throw std::runtime_error(stream.str());
}
// TODO: check if an implicit value was programmed for this argument
if (!m_is_used && !m_default_value.has_value() && m_is_required) {
std::stringstream stream;
Expand Down

0 comments on commit 37a1f3b

Please sign in to comment.