KiCad PCB EDA Suite
command.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 Mark Roszko <[email protected]>
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "command.h"
22#include <cli/exit_codes.h>
23#include <wx/crt.h>
24#include <macros.h>
25
26#include <sstream>
27
28
29CLI::COMMAND::COMMAND( const std::string& aName ) :
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}
39
40
42{
43 std::stringstream ss;
44 ss << m_argParser;
45 wxPrintf( FROM_UTF8( ss.str().c_str() ) );
46}
47
48
50{
51 if( m_argParser[ARG_HELP] == true )
52 {
53 PrintHelp();
54
55 return 0;
56 }
57
58 return doPerform( aKiway );
59}
60
61
63{
64 // default case if we aren't overloaded, just print the help
65 PrintHelp();
66
67 return EXIT_CODES::OK;
68}
virtual int doPerform(KIWAY &aKiway)
The internal handler that should be overloaded to implement command specific processing and work.
Definition: command.cpp:62
argparse::ArgumentParser m_argParser
Definition: command.h:68
COMMAND(const std::string &aName)
Define a new COMMAND instance.
Definition: command.cpp:29
void PrintHelp()
Definition: command.cpp:41
int Perform(KIWAY &aKiway)
Entry point to processing commands from args and doing work.
Definition: command.cpp:49
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
#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
This file contains miscellaneous commonly used macros and functions.
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 OK
Definition: exit_codes.h:30