Add a version command to cli and extend out a major.minor.patch string

This commit is contained in:
Marek Roszko 2023-01-01 22:41:05 -05:00
parent 6f16678d2d
commit f2fcd4b8e1
5 changed files with 112 additions and 18 deletions

View File

@ -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}\"

View File

@ -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 )

View File

@ -0,0 +1,37 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
* 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 <http://www.gnu.org/licenses/>.
*/
#include "command_version.h"
#include <cli/exit_codes.h>
#include <wx/crt.h>
#include <kicad_build_version.h>
CLI::VERSION_COMMAND::VERSION_COMMAND() : COMMAND( "version" )
{
}
int CLI::VERSION_COMMAND::doPerform( KIWAY& aKiway )
{
wxPrintf( KICAD_MAJOR_MINOR_PATCH_VERSION );
return 0;
}

View File

@ -0,0 +1,38 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
* 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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -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<COMMAND_ENTRY> commandStack = {
@ -208,6 +210,9 @@ static std::vector<COMMAND_ENTRY> 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;
}