Remove unused code in Argument::validate

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 <sean.robinson@scottsdalecc.edu>
This commit is contained in:
Sean Robinson 2022-04-27 08:00:17 -07:00
parent b9dd1ef8e3
commit 37a1f3b9e6

View File

@ -518,13 +518,6 @@ public:
void validate() const { void validate() const {
if (auto expected = maybe_nargs()) { if (auto expected = maybe_nargs()) {
if (m_is_optional) { 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 // TODO: check if an implicit value was programmed for this argument
if (!m_is_used && !m_default_value.has_value() && m_is_required) { if (!m_is_used && !m_default_value.has_value() && m_is_required) {
std::stringstream stream; std::stringstream stream;