KiCad PCB EDA Suite
CLI::COMMAND Class Reference

#include <command.h>

Inheritance diagram for CLI::COMMAND:
CLI::EXPORT_PCB_BASE_COMMAND CLI::EXPORT_PCB_COMMAND CLI::EXPORT_PCB_STEP_COMMAND CLI::EXPORT_SCH_COMMAND CLI::FP_COMMAND CLI::FP_EXPORT_COMMAND CLI::PCB_COMMAND CLI::SCH_COMMAND CLI::SYM_COMMAND CLI::SYM_EXPORT_COMMAND CLI::VERSION_COMMAND

Public Member Functions

 COMMAND (const std::string &aName)
 Define a new COMMAND instance. More...
 
int Perform (KIWAY &aKiway)
 Entry point to processing commands from args and doing work. More...
 
virtual ~COMMAND ()=default
 
argparse::ArgumentParser & GetArgParser ()
 
const std::string & GetName () const
 
void PrintHelp ()
 

Protected Member Functions

virtual int doPerform (KIWAY &aKiway)
 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 37 of file command.h.

Constructor & Destructor Documentation

◆ COMMAND()

CLI::COMMAND::COMMAND ( const std::string &  aName)

Define a new COMMAND instance.

Parameters
aNameThe name of the command that is to be used in the cli interface

Definition at line 29 of file command.cpp.

29 :
30 m_name( aName ),
31 m_argParser( aName, "", argparse::default_arguments::none )
32{
33 m_argParser.add_argument( ARG_HELP_SHORT, ARG_HELP )
34 .default_value( false )
35 .help( UTF8STDSTR( ARG_HELP_DESC ) )
36 .implicit_value( true )
37 .nargs( 0 );
38}
std::string m_name
Definition: command.h:67
argparse::ArgumentParser m_argParser
Definition: command.h:68
#define ARG_HELP
Definition: command.h:30
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_HELP_DESC
Definition: command.h:32
#define ARG_HELP_SHORT
Definition: command.h:31

References ARG_HELP, ARG_HELP_DESC, ARG_HELP_SHORT, m_argParser, and UTF8STDSTR.

◆ ~COMMAND()

virtual CLI::COMMAND::~COMMAND ( )
virtualdefault

Member Function Documentation

◆ doPerform()

int CLI::COMMAND::doPerform ( KIWAY aKiway)
protectedvirtual

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 in CLI::EXPORT_PCB_BASE_COMMAND, CLI::EXPORT_PCB_DRILL_COMMAND, CLI::EXPORT_PCB_DXF_COMMAND, CLI::EXPORT_PCB_GERBER_COMMAND, CLI::EXPORT_PCB_GERBERS_COMMAND, CLI::EXPORT_PCB_PDF_COMMAND, CLI::EXPORT_PCB_POS_COMMAND, CLI::EXPORT_PCB_STEP_COMMAND, CLI::EXPORT_PCB_SVG_COMMAND, CLI::EXPORT_SCH_NETLIST_COMMAND, CLI::EXPORT_SCH_PDF_COMMAND, CLI::EXPORT_SCH_PYTHONBOM_COMMAND, CLI::EXPORT_SCH_SVG_COMMAND, CLI::FP_EXPORT_SVG_COMMAND, CLI::FP_UPGRADE_COMMAND, CLI::SYM_EXPORT_SVG_COMMAND, CLI::SYM_UPGRADE_COMMAND, and CLI::VERSION_COMMAND.

Definition at line 62 of file command.cpp.

63{
64 // default case if we aren't overloaded, just print the help
65 PrintHelp();
66
67 return EXIT_CODES::OK;
68}
void PrintHelp()
Definition: command.cpp:41
static const int OK
Definition: exit_codes.h:30

References CLI::EXIT_CODES::OK.

◆ GetArgParser()

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

Definition at line 54 of file command.h.

54{ return m_argParser; }

References m_argParser.

Referenced by recurseArgParserBuild(), and recurseArgParserSubCommandUsed().

◆ GetName()

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

Definition at line 55 of file command.h.

55{ return m_name; }

References m_name.

Referenced by recurseArgParserSubCommandUsed().

◆ Perform()

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

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

References ARG_HELP.

◆ PrintHelp()

void CLI::COMMAND::PrintHelp ( )

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}
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

References FROM_UTF8().

Member Data Documentation

◆ m_argParser

◆ m_name

std::string CLI::COMMAND::m_name
protected

Definition at line 67 of file command.h.

Referenced by GetName().


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