KiCad PCB EDA Suite
CLI::VERSION_COMMAND Class Reference

#include <command_version.h>

Inheritance diagram for CLI::VERSION_COMMAND:
CLI::COMMAND

Public Member Functions

 VERSION_COMMAND ()
 
int Perform (KIWAY &aKiway)
 Entry point to processing commands from args and doing work. More...
 
argparse::ArgumentParser & GetArgParser ()
 
const std::string & GetName () const
 
void PrintHelp ()
 

Protected Member Functions

int doPerform (KIWAY &aKiway) override
 The internal handler that should be overloaded to implement command specific processing and work. More...
 

Protected Attributes

std::string m_name
 
argparse::ArgumentParser m_argParser
 

Detailed Description

Definition at line 28 of file command_version.h.

Constructor & Destructor Documentation

◆ VERSION_COMMAND()

CLI::VERSION_COMMAND::VERSION_COMMAND ( )

Definition at line 31 of file command_version.cpp.

31 : COMMAND( "version" )
32{
33 m_argParser.add_argument( ARG_FORMAT )
34 .default_value( std::string( "plain" ) )
35 .help( UTF8STDSTR( _( "version info format (plain, commit, about)" ) ) );
36}
argparse::ArgumentParser m_argParser
Definition: command.h:68
COMMAND(const std::string &aName)
Define a new COMMAND instance.
Definition: command.cpp:29
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_FORMAT
#define _(s)

References _, ARG_FORMAT, CLI::COMMAND::m_argParser, and UTF8STDSTR.

Member Function Documentation

◆ doPerform()

int CLI::VERSION_COMMAND::doPerform ( KIWAY aKiway)
overrideprotectedvirtual

The internal handler that should be overloaded to implement command specific processing and work.

If not overloaded, the command will simply emit the help options by default

Reimplemented from CLI::COMMAND.

Definition at line 39 of file command_version.cpp.

40{
41 if( !m_argParser )
42 {
43 // were we redirected from the --version?
44 // m_argParser override for bool() returns false if we didnt parse any args normally
45 // we need to exit here early because it'll exception in the later arg handling code if we dont
46 // no arg provided also ends up here on the version command
47 wxPrintf( "%s\n", GetMajorMinorPatchVersion() );
48 return EXIT_CODES::OK;
49 }
50
51 wxString format = FROM_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
52 if( format == wxS( "plain" ) )
53 {
54 wxPrintf( "%s\n", GetMajorMinorPatchVersion() );
55 }
56 else if( format == wxS( "commit" ) )
57 {
58 wxPrintf( "%s\n", GetCommitHash() );
59 }
60 else if( format == wxS( "about" ) )
61 {
62 wxString msg_version = GetVersionInfoData( wxS( "kicad-cli" ) );
63 wxPrintf( "%s\n", msg_version );
64 }
65 else
66 {
67 wxFprintf( stderr, _( "Invalid format\n" ) );
69 }
70
71 return EXIT_CODES::OK;
72}
wxString GetVersionInfoData(const wxString &aTitle, bool aHtml, bool aBrief)
Create a version info string for bug reports and the about dialog.
wxString GetCommitHash()
Get the commit hash as a string.
wxString GetMajorMinorPatchVersion()
Get the major, minor and patch version in a string major.minor.patch This is extracted by CMake from ...
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
static const int ERR_ARGS
Definition: exit_codes.h:31
static const int OK
Definition: exit_codes.h:30

References _, ARG_FORMAT, CLI::EXIT_CODES::ERR_ARGS, FROM_UTF8(), GetCommitHash(), GetMajorMinorPatchVersion(), GetVersionInfoData(), and CLI::EXIT_CODES::OK.

◆ GetArgParser()

argparse::ArgumentParser & CLI::COMMAND::GetArgParser ( )
inlineinherited

Definition at line 54 of file command.h.

54{ return m_argParser; }

References CLI::COMMAND::m_argParser.

Referenced by recurseArgParserBuild(), and recurseArgParserSubCommandUsed().

◆ GetName()

const std::string & CLI::COMMAND::GetName ( void  ) const
inlineinherited

Definition at line 55 of file command.h.

55{ return m_name; }
std::string m_name
Definition: command.h:67

References CLI::COMMAND::m_name.

Referenced by recurseArgParserSubCommandUsed().

◆ Perform()

int CLI::COMMAND::Perform ( KIWAY aKiway)
inherited

Entry point to processing commands from args and doing work.

Definition at line 49 of file command.cpp.

50{
51 if( m_argParser[ARG_HELP] == true )
52 {
53 PrintHelp();
54
55 return 0;
56 }
57
58 return doPerform( aKiway );
59}
virtual int doPerform(KIWAY &aKiway)
The internal handler that should be overloaded to implement command specific processing and work.
Definition: command.cpp:62
void PrintHelp()
Definition: command.cpp:41
#define ARG_HELP
Definition: command.h:30

References ARG_HELP.

◆ PrintHelp()

void CLI::COMMAND::PrintHelp ( )
inherited

Definition at line 41 of file command.cpp.

42{
43 std::stringstream ss;
44 ss << m_argParser;
45 wxPrintf( FROM_UTF8( ss.str().c_str() ) );
46}

References FROM_UTF8().

Member Data Documentation

◆ m_argParser

◆ m_name

std::string CLI::COMMAND::m_name
protectedinherited

Definition at line 67 of file command.h.

Referenced by CLI::COMMAND::GetName().


The documentation for this class was generated from the following files: