Reporter command line parser errors more eagerly

- show all “unrecognised option” errors
This commit is contained in:
Phil Nash 2013-12-20 19:06:02 +00:00
parent f385a0b13d
commit 886d9d397c
3 changed files with 35 additions and 23 deletions

View file

@ -142,9 +142,8 @@ namespace Catch {
int applyCommandLine( int argc, char* const argv[], OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) {
try {
m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail );
m_unusedTokens = m_cli.parseInto( argc, argv, m_configData );
if( unusedOptionBehaviour == OnUnusedOptions::Fail )
enforceNoUsedTokens();
if( m_configData.showHelp )
showHelp( m_configData.processName );
m_config.reset();
@ -152,7 +151,7 @@ namespace Catch {
catch( std::exception& ex ) {
{
Colour colourGuard( Colour::Red );
std::cerr << "\nError in input:\n"
std::cerr << "\nError(s) in input:\n"
<< Text( ex.what(), TextAttributes().setIndent(2) )
<< "\n\n";
}
@ -167,18 +166,6 @@ namespace Catch {
m_config.reset();
}
void enforceNoUsedTokens() const {
if( !m_unusedTokens.empty() ) {
std::vector<Clara::Parser::Token>::const_iterator
it = m_unusedTokens.begin(),
itEnd = m_unusedTokens.end();
std::string msg;
for(; it != itEnd; ++it )
msg += " unrecognised option: " + it->data + "\n";
throw std::runtime_error( msg.substr( 0, msg.size()-1 ) );
}
}
int run( int argc, char* const argv[] ) {
int returnCode = applyCommandLine( argc, argv );