Report back the correct arg info for a failed cli command

This commit is contained in:
Marek Roszko 2022-11-13 14:24:44 -05:00
parent 5b92f81385
commit e144f05a4f
1 changed files with 16 additions and 1 deletions

View File

@ -233,7 +233,22 @@ int PGM_KICAD::OnPgmRun()
catch( const std::runtime_error& err )
{
std::cout << err.what() << std::endl;
std::cout << argParser;
// find the correct argparser object to output the command usage info
COMMAND_ENTRY* cliCmd = nullptr;
for( COMMAND_ENTRY& entry : commandStack )
{
if( argParser.is_subcommand_used( entry.handler->GetName() ) )
{
cliCmd = recurseArgParserSubCommandUsed( argParser, entry );
}
}
if( cliCmd )
std::cout << cliCmd->handler->GetArgParser();
else
std::cout << argParser;
return CLI::EXIT_CODES::ERR_ARGS;
}