26#include <wx/filename.h>
28#include <wx/stdpaths.h>
29#include <wx/wxcrtvararg.h>
111 wxLogFatalError( wxT(
"Unexpected call to Kiface() in kicad/kicad.cpp" ) );
113 throw std::logic_error(
"Unexpected call to Kiface() in kicad/kicad.cpp" );
339static void printHelp( argparse::ArgumentParser& argParser )
341 std::stringstream ss;
343 wxPrintf(
From_UTF8( ss.str().c_str() ) );
355 if( aValue.empty() || aValue[0] !=
'-' )
358 if( aValue.find(
',' ) == std::string::npos )
361 for(
size_t i = 1; i < aValue.size(); ++i )
365 if( !std::isdigit( c ) && c !=
'.' && c !=
',' && c !=
'-' && c !=
'+' )
386 std::vector<std::string>
result;
388 static const std::set<std::string> vectorArgs = {
389 "--rotate",
"--pan",
"--pivot"
392 for(
int i = 0; i < argc; ++i )
394 std::string current( argv[i] );
396 if( vectorArgs.count( current ) && i + 1 < argc )
398 std::string
next( argv[i + 1] );
402 result.push_back( current +
"='" +
next +
"'" );
408 result.push_back( current );
418 App().SetAppDisplayName( wxT(
"kicad-cli" ) );
421 wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
423 if( !wxIsAbsolutePath( absoluteArgv0 ) )
425 wxLogError( wxT(
"No meaningful argv[0]" ) );
433 m_bm.InitSettings(
new KICAD_SETTINGS );
446 argparse::ArgumentParser argParser( std::string(
"kicad-cli" ),
GetMajorMinorVersion().ToStdString(),
447 argparse::default_arguments::none );
450 .help(
UTF8STDSTR(
_(
"prints version information and exits" ) ) )
473 argParser.parse_args( args );
476 catch(
const std::exception& err )
478 bool requestedHelp =
false;
484 requestedHelp =
true;
490 wxPrintf(
"%s\n", err.what() );
493 COMMAND_ENTRY* cliCmd =
nullptr;
496 if( argParser.is_subcommand_used( entry.handler->GetName() ) )
517 std::stringstream ss;
519 wxPrintf(
From_UTF8( ss.str().c_str() ) );
524 CLI::COMMAND* cliCmd =
nullptr;
536 if( argParser.is_subcommand_used( entry.handler->GetName() ) )
539 if( cmdSubEntry !=
nullptr )
593#if defined( __WXMAC__ )
594 wxFAIL_MSG(
"kicad-cli should not call MacOpenFile" );
638 if( wxGetEnv( wxS(
"KICAD_ENABLE_WXTRACE" ),
nullptr ) )
640 wxLog::EnableLogging(
true );
641 wxLog::SetLogLevel( wxLOG_Trace );
658#if defined( __FreeBSD__ )
660 wxLog::EnableLogging(
false );
663 return wxAppConsole::OnExit();
689 bool ProcessEvent( wxEvent& aEvent )
override
691 if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
693 wxKeyEvent* keyEvent =
static_cast<wxKeyEvent*
>( &aEvent );
712 bool OnExceptionInMainLoop()
override
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
argparse::ArgumentParser & GetArgParser()
const std::string & GetName() const
int Perform(KIWAY &aKiway)
Entry point to processing commands from args and doing work.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
void LoadGlobalTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the global library tables in the given list, or all tables if no list is given
virtual wxApp & App()
Return a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
char ** m_argvUtf8
argv parameters converted to utf8 form because wxWidgets has opinions.
void HandleException(std::exception_ptr aPtr, bool aUnhandled=false)
A exception handler to be used at the top level if exceptions bubble up that for.
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
bool InitPgm(bool aHeadless=false, bool aIsUnitTest=false)
Initialize this program.
virtual SETTINGS_MANAGER & GetSettingsManager() const
virtual LIBRARY_MANAGER & GetLibraryManager() const
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
PGM_KICAD extends PGM_BASE to bring in FileHistory() and PdfBrowser() which were moved from EDA_APP i...
void MacOpenFile(const wxString &aFileName) override
Specific to MacOSX (not used under Linux or Windows).
APP_SETTINGS_BASE * PgmSettings()
Container for project specific data.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
static CLI::PCB_EXPORT_SVG_COMMAND exportPcbSvgCmd
static CLI::SCH_EXPORT_PLOT_COMMAND exportSchHpglCmd
static CLI::SCH_EXPORT_PLOT_COMMAND exportSchSvgCmd
static CLI::PCB_EXPORT_3D_COMMAND exportPcbVrmlCmd
static CLI::PCB_EXPORT_STATS_COMMAND exportPcbStatsCmd
static CLI::PCB_EXPORT_DXF_COMMAND exportPcbDxfCmd
static CLI::SCH_ERC_COMMAND schErcCmd
static CLI::PCB_EXPORT_HPGL_COMMAND exportPcbHpglCmd
static CLI::PCB_DRC_COMMAND pcbDrcCmd
static std::vector< std::string > preprocessArgs(int argc, char **argv)
Pre-process command line arguments to handle negative numeric values.
static CLI::PCB_IMPORT_COMMAND pcbImportCmd
static CLI::FP_EXPORT_SVG_COMMAND fpExportSvgCmd
static CLI::PCB_EXPORT_COMMAND exportPcbCmd
static CLI::PCB_RENDER_COMMAND pcbRenderCmd
static bool looksLikeNegativeVectorValue(const std::string &aValue)
Check if a string looks like a numeric vector value that happens to start with a minus sign.
static CLI::SYM_UPGRADE_COMMAND symUpgradeCmd
static CLI::FP_EXPORT_COMMAND fpExportCmd
static CLI::SCH_EXPORT_PYTHONBOM_COMMAND exportSchPythonBomCmd
static CLI::FP_UPGRADE_COMMAND fpUpgradeCmd
static CLI::SCH_EXPORT_PLOT_COMMAND exportSchPdfCmd
static void printHelp(argparse::ArgumentParser &argParser)
static CLI::JOBSET_RUN_COMMAND jobsetRunCmd
static CLI::PCB_UPGRADE_COMMAND pcbUpgradeCmd
static CLI::PCB_EXPORT_POS_COMMAND exportPcbPosCmd
static CLI::PCB_EXPORT_PS_COMMAND exportPcbPsCmd
static CLI::SYM_COMMAND symCmd
static CLI::PCB_EXPORT_3D_COMMAND exportPcbStepCmd
static CLI::PCB_EXPORT_3D_COMMAND exportPcbPlyCmd
static CLI::PCB_EXPORT_GERBERS_COMMAND exportPcbGerbersCmd
static CLI::SCH_EXPORT_BOM_COMMAND exportSchBomCmd
static CLI::PCB_EXPORT_IPCD356_COMMAND exportPcbIpcD356Cmd
static CLI::SCH_COMMAND schCmd
static CLI::PCB_COMMAND pcbCmd
static CLI::PCB_EXPORT_3D_COMMAND exportPcb3DPDFCmd
static std::vector< COMMAND_ENTRY > commandStack
static CLI::PCB_EXPORT_DRILL_COMMAND exportPcbDrillCmd
static CLI::PCB_EXPORT_IPC2581_COMMAND exportPcbIpc2581Cmd
static CLI::SCH_EXPORT_PLOT_COMMAND exportSchDxfCmd
static CLI::JOBSET_COMMAND jobsetCmd
static CLI::SYM_EXPORT_COMMAND symExportCmd
static CLI::SYM_EXPORT_SVG_COMMAND symExportSvgCmd
static COMMAND_ENTRY * recurseArgParserSubCommandUsed(argparse::ArgumentParser &aArgParser, COMMAND_ENTRY &aEntry)
static CLI::PCB_EXPORT_3D_COMMAND exportPcbU3DCmd
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static CLI::PCB_EXPORT_ODB_COMMAND exportPcbOdbCmd
static CLI::VERSION_COMMAND versionCmd
static CLI::PCB_EXPORT_3D_COMMAND exportPcbStlCmd
static CLI::PCB_EXPORT_PDF_COMMAND exportPcbPdfCmd
static CLI::SCH_UPGRADE_COMMAND schUpgradeCmd
static CLI::PCB_EXPORT_3D_COMMAND exportPcbXaoCmd
static void recurseArgParserBuild(argparse::ArgumentParser &aArgParser, COMMAND_ENTRY &aEntry)
static CLI::SCH_EXPORT_NETLIST_COMMAND exportSchNetlistCmd
static CLI::SCH_EXPORT_PLOT_COMMAND exportSchPostscriptCmd
static CLI::PCB_EXPORT_GENCAD_COMMAND exportPcbGencadCmd
static CLI::PCB_EXPORT_3D_COMMAND exportPcbStepzCmd
static CLI::FP_COMMAND fpCmd
static CLI::PCB_EXPORT_3D_COMMAND exportPcbGlbCmd
static CLI::SCH_EXPORT_COMMAND exportSchCmd
static CLI::PCB_EXPORT_3D_COMMAND exportPcbBrepCmd
#define KFCTL_CPP_PROJECT_SUITE
Running under C++ project mgr, possibly with others.
#define KFCTL_CLI
Running as CLI app.
static const int ERR_ARGS
static const int AVOID_CLOSING
void SetPgm(PGM_BASE *pgm)
PGM_BASE & Pgm()
The global program "get" accessor.
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< FAB_LAYER_COLOR > dummy
wxString From_UTF8(const char *cstring)
Not publicly visible because most of the action is in PGM_KICAD these days.
int FilterEvent(wxEvent &aEvent) override
COMMAND_ENTRY(CLI::COMMAND *aHandler)
COMMAND_ENTRY(CLI::COMMAND *aHandler, std::vector< COMMAND_ENTRY > aSub)
std::vector< COMMAND_ENTRY > subCommands
System directories search utilities.
wxString result
Test unit parsing edge cases and error handling.
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.