From e144f05a4f2052f6cb21b0608d9262ab7e1261a9 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sun, 13 Nov 2022 14:24:44 -0500 Subject: [PATCH] Report back the correct arg info for a failed cli command --- kicad/kicad_cli.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index 7d7151ad6d..516af4068a 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -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; }