diff --git a/cmake/BuildSteps/WriteVersionHeader.cmake b/cmake/BuildSteps/WriteVersionHeader.cmake index 6c6def6bbb..e079dc95a7 100644 --- a/cmake/BuildSteps/WriteVersionHeader.cmake +++ b/cmake/BuildSteps/WriteVersionHeader.cmake @@ -75,6 +75,7 @@ set( _wvh_new_version_text #define KICAD_PATCH_VERSION \"${KICAD_PATCH_VERSION}\" #define KICAD_IS_NIGHTLY ${KICAD_IS_NIGHTLY} #define KICAD_MAJOR_MINOR_VERSION \"${KICAD_MAJOR_MINOR_VERSION}\" +#define KICAD_MAJOR_MINOR_PATCH_VERSION \"${KICAD_MAJOR_MINOR_PATCH_VERSION}\" #define KICAD_MAJOR_MINOR_PATCH_TUPLE ${KICAD_MAJOR_MINOR_PATCH_TUPLE} #define KICAD_WIN32_RC_PRODVER ${KICAD_WIN32_RC_PRODVER} #define KICAD_WIN32_RC_PRODVER_STR \"${KICAD_WIN32_RC_PRODVER_STR}\" diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt index 29f10e0b73..dd3ee0f2ca 100644 --- a/kicad/CMakeLists.txt +++ b/kicad/CMakeLists.txt @@ -52,6 +52,7 @@ set( KICAD_CLI_SRCS cli/command_export_sch_svg.cpp cli/command_sym_export_svg.cpp cli/command_sym_upgrade.cpp + cli/command_version.cpp ) if( WIN32 ) diff --git a/kicad/cli/command_version.cpp b/kicad/cli/command_version.cpp new file mode 100644 index 0000000000..e4ef5db8f2 --- /dev/null +++ b/kicad/cli/command_version.cpp @@ -0,0 +1,37 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 Mark Roszko + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "command_version.h" +#include +#include +#include + + +CLI::VERSION_COMMAND::VERSION_COMMAND() : COMMAND( "version" ) +{ +} + + +int CLI::VERSION_COMMAND::doPerform( KIWAY& aKiway ) +{ + wxPrintf( KICAD_MAJOR_MINOR_PATCH_VERSION ); + + return 0; +} \ No newline at end of file diff --git a/kicad/cli/command_version.h b/kicad/cli/command_version.h new file mode 100644 index 0000000000..198950fc62 --- /dev/null +++ b/kicad/cli/command_version.h @@ -0,0 +1,38 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 Mark Roszko + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef COMMAND_VERSION_H +#define COMMAND_VERSION_H + +#include "command.h" + +namespace CLI +{ +class VERSION_COMMAND : public COMMAND +{ +public: + VERSION_COMMAND(); + +protected: + int doPerform( KIWAY& aKiway ) override; +}; +} + +#endif \ No newline at end of file diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index 656a058727..b046e44141 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -71,6 +71,7 @@ #include "cli/command_sym_export.h" #include "cli/command_sym_export_svg.h" #include "cli/command_sym_upgrade.h" +#include "cli/command_version.h" #include "cli/exit_codes.h" #include "cli/cli_names.h" @@ -145,6 +146,7 @@ static CLI::SYM_COMMAND symCmd{}; static CLI::SYM_EXPORT_COMMAND symExportCmd{}; static CLI::SYM_EXPORT_SVG_COMMAND symExportSvgCmd{}; static CLI::SYM_UPGRADE_COMMAND symUpgradeCmd{}; +static CLI::VERSION_COMMAND versionCmd{}; static std::vector commandStack = { @@ -208,6 +210,9 @@ static std::vector commandStack = { } } }, + { + &versionCmd, + } }; @@ -244,6 +249,14 @@ static COMMAND_ENTRY* recurseArgParserSubCommandUsed( argparse::ArgumentParser& } +static void printHelp( argparse::ArgumentParser& argParser ) +{ + std::stringstream ss; + ss << argParser; + wxPrintf( FROM_UTF8( ss.str().c_str() ) ); +} + + bool PGM_KICAD::OnPgmInit() { PGM_BASE::BuildArgvUtf8(); @@ -321,21 +334,12 @@ int PGM_KICAD::OnPgmRun() cliCmd->handler->PrintHelp(); else { - std::stringstream ss; - ss << argParser; - wxPrintf( FROM_UTF8( ss.str().c_str() ) ); + printHelp( argParser ); } return CLI::EXIT_CODES::ERR_ARGS; } - if( argParser[ ARG_VERSION ] == true ) - { - wxPrintf( KICAD_MAJOR_MINOR_VERSION ); - - return 0; - } - if( argParser[ ARG_HELP ] == true ) { std::stringstream ss; @@ -345,18 +349,33 @@ int PGM_KICAD::OnPgmRun() return 0; } - COMMAND_ENTRY* cliCmd = nullptr; - for( COMMAND_ENTRY& entry : commandStack ) + CLI::COMMAND* cliCmd = nullptr; + + // the version arg gets redirected to the version subcommand + if( argParser[ARG_VERSION] == true ) { - if( argParser.is_subcommand_used( entry.handler->GetName() ) ) + cliCmd = &versionCmd; + } + + if( !cliCmd ) + { + for( COMMAND_ENTRY& entry : commandStack ) { - cliCmd = recurseArgParserSubCommandUsed( argParser, entry ); + if( argParser.is_subcommand_used( entry.handler->GetName() ) ) + { + COMMAND_ENTRY* cmdSubEntry = recurseArgParserSubCommandUsed( argParser, entry ); + if( cmdSubEntry != nullptr ) + { + cliCmd = cmdSubEntry->handler; + break; + } + } } } if( cliCmd ) { - int exitCode = cliCmd->handler->Perform( Kiway ); + int exitCode = cliCmd->Perform( Kiway ); if( exitCode != CLI::EXIT_CODES::AVOID_CLOSING ) { @@ -369,9 +388,7 @@ int PGM_KICAD::OnPgmRun() } else { - std::stringstream ss; - ss << argParser; - wxPrintf( FROM_UTF8( ss.str().c_str() ) ); + printHelp( argParser ); return CLI::EXIT_CODES::ERR_ARGS; }