Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit c58c402

Browse files
committed
Clearer error when parsing a subcommand fails
1 parent ac4a601 commit c58c402

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

include/clara.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ namespace detail {
100100
void loadBuffer() {
101101
m_tokenBuffer.resize( 0 );
102102

103-
// Skip any empty strings
104-
while( it != itEnd && it->empty() )
105-
++it;
103+
// Note: not skiping empty strings
106104

107105
if( it != itEnd ) {
108106
auto const &next = *it;
@@ -962,10 +960,13 @@ namespace detail {
962960
for( auto const& opt : m_options ) parsers[i++] = &opt;
963961
for( auto const& arg : m_args ) parsers[i++] = &arg;
964962

965-
if( m_isSubcmd )
966-
m_exeName.set( tokens->token );
967-
else
968-
m_exeName.set( exeName );
963+
if (m_isSubcmd) {
964+
if (auto result = m_exeName.set(tokens->token); !result)
965+
return InternalParseResult(result);
966+
}
967+
else {
968+
m_exeName.set(exeName);
969+
}
969970

970971
auto result = InternalParseResult::ok( m_isSubcmd ?
971972
ParseState( ParseResultType::Matched, ++TokenStream( tokens ) ) :

0 commit comments

Comments
 (0)