KiCad PCB EDA Suite
command_version.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_version.h"
22#include <cli/exit_codes.h>
23#include <wx/crt.h>
24#include <build_version.h>
25
26#include <macros.h>
27#include <build_version.h>
28
29#define ARG_FORMAT "--format"
30
32{
33 m_argParser.add_argument( ARG_FORMAT )
34 .default_value( std::string( "plain" ) )
35 .help( UTF8STDSTR( _( "version info format (plain, commit, about)" ) ) );
36}
37
38
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 ...
argparse::ArgumentParser m_argParser
Definition: command.h:68
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_FORMAT
#define _(s)
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 ERR_ARGS
Definition: exit_codes.h:31
static const int OK
Definition: exit_codes.h:30