KiCad PCB EDA Suite
Loading...
Searching...
No Matches
utility_program.h
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) 2018 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef UTILITY_PROGRAM_H
25#define UTILITY_PROGRAM_H
26
27#include <functional>
28#include <iostream>
29#include <string>
30#include <vector>
31
32namespace KI_TEST
33{
34
39{
41 OK = 0,
42
45
48
51};
52
53
69{
71 using FUNC = std::function<int( int argc, char** argv )>;
72
73 UTILITY_PROGRAM( const std::string& aName, const std::string& aDesc, FUNC aMainFunc )
74 : m_name( aName ), m_desc( aDesc ), m_func( aMainFunc )
75 {
76 }
77
78 UTILITY_PROGRAM() : m_func( nullptr )
79 {
80 }
81
83 std::string m_name;
84
86 std::string m_desc;
87
90};
91
92
98{
99public:
100
112 int HandleCommandLine( int argc, char** argv ) const;
113
114private:
119 void showSubUtilityList( std::ostream& os ) const;
120
126 UTILITY_PROGRAM::FUNC* findSubUtility( const std::string& aName ) const;
127
133 void printUsage( char* name, std::ostream& os ) const;
134};
135
136} // namespace KI_TEST
137
138#endif // UTILITY_PROGRAM_H
const char * name
Definition: DXF_plotter.cpp:57
Class that handles delegation of command lines to one of a number of "sub-utilities".
UTILITY_PROGRAM::FUNC * findSubUtility(const std::string &aName) const
Find a sub-utility with the given ID/name.
void showSubUtilityList(std::ostream &os) const
Format the list of known sub-utils.
void printUsage(char *name, std::ostream &os) const
Print the command line usage of this program.
int HandleCommandLine(int argc, char **argv) const
Take in a command line and:
RET_CODES
Return codes for tools.
@ OK
Tool exited OK.
@ UNKNOWN_TOOL
The tool asked for was not found.
@ TOOL_SPECIFIC
Tools can define their own statuses from here onwards.
@ BAD_CMDLINE
The command line was not correct for the tool.
Description of a "utility program", which is a program that takes some command line and does "somethi...
std::function< int(int argc, char **argv)> FUNC
A function that provides the program for a given command line.
std::string m_name
The name of the program (this is used to select one)
UTILITY_PROGRAM(const std::string &aName, const std::string &aDesc, FUNC aMainFunc)
FUNC m_func
The function to call to run the program.
std::string m_desc
Description of the program.