KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 <string_utils.h>
27#include <build_version.h>
28
29
30#define ARG_FORMAT "--format"
31
32
34{
35 m_argParser.add_description( UTF8STDSTR( _( "Reports the version info in various formats" ) ) );
36
37 m_argParser.add_argument( ARG_FORMAT )
38 .default_value( std::string( "plain" ) )
39 .help( UTF8STDSTR( _( "version info format (plain, commit, about)" ) ) );
40}
41
42
44{
45 if( !m_argParser )
46 {
47 // were we redirected from the --version?
48 // m_argParser override for bool() returns false if we didnt parse any args normally
49 // we need to exit here early because it'll exception in the later arg handling code
50 // if we don't no arg provided also ends up here on the version command
51 wxPrintf( "%s\n", GetMajorMinorPatchVersion() );
52 return EXIT_CODES::OK;
53 }
54
55 wxString format = From_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
56 if( format == wxS( "plain" ) )
57 {
58 wxPrintf( "%s\n", GetMajorMinorPatchVersion() );
59 }
60 else if( format == wxS( "commit" ) )
61 {
62 wxPrintf( "%s\n", GetCommitHash() );
63 }
64 else if( format == wxS( "about" ) )
65 {
66 wxString msg_version = GetVersionInfoData( wxS( "kicad-cli" ) );
67 wxPrintf( "%s\n", msg_version );
68 }
69 else
70 {
71 wxFprintf( stderr, _( "Invalid format\n" ) );
73 }
74
75 return EXIT_CODES::OK;
76}
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:100
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)
static const int ERR_ARGS
Definition: exit_codes.h:31
static const int OK
Definition: exit_codes.h:30
wxString From_UTF8(const char *cstring)