From 40c50c94fb4f707c6db40161e24252541b7293fe Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 24 Aug 2025 07:36:52 -0700 Subject: [PATCH] Help is always valid Return 0 and no error, just help when the --help flag is present Fixes https://gitlab.com/kicad/code/kicad/-/issues/21538 (cherry picked from commit 9dc76f658d34a0622ef4a4160ec8390e645f3ad4) --- kicad/kicad_cli.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index 883458aa2d..19126826d1 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -356,7 +356,19 @@ int PGM_KICAD::OnPgmRun() // std::runtime_error doesn't seem to be enough for the scan<>() catch( const std::exception& err ) { - wxPrintf( "%s\n", err.what() ); + bool requestedHelp = false; + + for( int i = 0; i < m_argcUtf8; ++i ) + { + if( std::string arg( m_argvUtf8[i] ); arg == ARG_HELP_SHORT || arg == ARG_HELP ) + { + requestedHelp = true; + break; + } + } + + if( !requestedHelp ) + wxPrintf( "%s\n", err.what() ); // find the correct argparser object to output the command usage info COMMAND_ENTRY* cliCmd = nullptr; @@ -378,7 +390,7 @@ int PGM_KICAD::OnPgmRun() printHelp( argParser ); } - return CLI::EXIT_CODES::ERR_ARGS; + return requestedHelp ? 0 : CLI::EXIT_CODES::ERR_ARGS; } if( argParser[ ARG_HELP ] == true )