CLI: parameterize whether export job inputs are directories or files

This commit is contained in:
Graham Keeth 2023-09-19 01:47:41 +00:00 committed by Mark Roszko
parent 1635df57a3
commit 5dc62368b0
16 changed files with 36 additions and 25 deletions

View File

@ -112,7 +112,7 @@ int CLI::COMMAND::doPerform( KIWAY& aKiway )
}
void CLI::COMMAND::addCommonArgs( bool aInput, bool aOutput, bool aOutputIsDir )
void CLI::COMMAND::addCommonArgs( bool aInput, bool aOutput, bool aInputIsDir, bool aOutputIsDir )
{
m_hasInputArg = aInput;
m_hasOutputArg = aOutput;
@ -120,9 +120,18 @@ void CLI::COMMAND::addCommonArgs( bool aInput, bool aOutput, bool aOutputIsDir )
if( aInput )
{
m_argParser.add_argument( ARG_INPUT )
.help( UTF8STDSTR( _( "Input file" ) ) )
.metavar( "INPUT_FILE" );
if( aInputIsDir )
{
m_argParser.add_argument( ARG_INPUT )
.help( UTF8STDSTR( _( "Input directory" ) ) )
.metavar( "INPUT_DIR" );
}
else
{
m_argParser.add_argument( ARG_INPUT )
.help( UTF8STDSTR( _( "Input file" ) ) )
.metavar( "INPUT_FILE" );
}
}
if( aOutput )
@ -138,7 +147,7 @@ void CLI::COMMAND::addCommonArgs( bool aInput, bool aOutput, bool aOutputIsDir )
{
m_argParser.add_argument( "-o", ARG_OUTPUT )
.default_value( std::string() )
.help( UTF8STDSTR( _( "Output file name" ) ) )
.help( UTF8STDSTR( _( "Output file" ) ) )
.metavar( "OUTPUT_FILE" );
}
}
@ -166,4 +175,4 @@ void CLI::COMMAND::addDefineArg()
_( "Overrides or adds project variables, can be used multiple times to declare multiple variables."
"\nUse in the format of '--define-var key=value' or '-D key=value'" ) ) )
.metavar( "KEY=VALUE" );
}
}

View File

@ -67,9 +67,10 @@ protected:
*
* @param aInput Configures the input arg
* @param aOutput Configures the output arg
* @param aInputIsDir Configures whether the input arg description will be for a file or directory
* @param aOutputIsDir Configures whether the output arg description will be for a file or directory
*/
void addCommonArgs( bool aInput, bool aOutput, bool aOutputIsDir );
void addCommonArgs( bool aInput, bool aOutput, bool aInputIsDir, bool aOutputIsDir );
/**
* Sets up the drawing sheet arg used by many of the export commands

View File

@ -32,7 +32,7 @@
#define ARG_FOOTPRINT "--footprint"
CLI::FP_EXPORT_SVG_COMMAND::FP_EXPORT_SVG_COMMAND() : PCB_EXPORT_BASE_COMMAND( "svg" )
CLI::FP_EXPORT_SVG_COMMAND::FP_EXPORT_SVG_COMMAND() : PCB_EXPORT_BASE_COMMAND( "svg", true )
{
m_argParser.add_description( UTF8STDSTR( _( "Exports the footprint or entire footprint library to SVG" ) ) );

View File

@ -30,7 +30,7 @@
#define ARG_FORCE "--force"
CLI::FP_UPGRADE_COMMAND::FP_UPGRADE_COMMAND() : PCB_EXPORT_BASE_COMMAND( "upgrade" )
CLI::FP_UPGRADE_COMMAND::FP_UPGRADE_COMMAND() : PCB_EXPORT_BASE_COMMAND( "upgrade", true, true )
{
m_argParser.add_description( UTF8STDSTR( _( "Upgrades the footprint library to the current kicad version format" ) ) );

View File

@ -40,7 +40,7 @@
CLI::PCB_DRC_COMMAND::PCB_DRC_COMMAND() : COMMAND( "drc" )
{
addCommonArgs( true, true, false );
addCommonArgs( true, true, false, false );
addDefineArg();
m_argParser.add_description( UTF8STDSTR( _( "Runs the Design Rules Check (DRC) on the PCB and creates a report" ) ) );

View File

@ -55,7 +55,7 @@ CLI::PCB_EXPORT_3D_COMMAND::PCB_EXPORT_3D_COMMAND( const std::string& aNa
m_format( aFormat )
{
m_argParser.add_description( aDescription );
addCommonArgs( true, true, false );
addCommonArgs( true, true, false, false );
addDefineArg();
if( m_format == JOB_EXPORT_PCB_3D::FORMAT::UNKNOWN )

View File

@ -30,6 +30,7 @@
#include <wx/crt.h>
CLI::PCB_EXPORT_BASE_COMMAND::PCB_EXPORT_BASE_COMMAND( const std::string& aName,
bool aInputIsDir,
bool aOutputIsDir ) :
COMMAND( aName )
{
@ -37,7 +38,7 @@ CLI::PCB_EXPORT_BASE_COMMAND::PCB_EXPORT_BASE_COMMAND( const std::string& aName,
m_requireLayers = false;
m_hasLayerArg = false;
addCommonArgs( true, true, aOutputIsDir );
addCommonArgs( true, true, aInputIsDir, aOutputIsDir );
// Build list of layer names and their layer mask:
for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )

View File

@ -42,7 +42,7 @@ namespace CLI
struct PCB_EXPORT_BASE_COMMAND : public COMMAND
{
PCB_EXPORT_BASE_COMMAND( const std::string& aName, bool aOutputIsDir = false );
PCB_EXPORT_BASE_COMMAND( const std::string& aName, bool aInputIsDir = false, bool aOutputIsDir = false );
protected:
int doPerform( KIWAY& aKiway ) override;

View File

@ -41,7 +41,7 @@
#define ARG_MAP_FORMAT "--map-format"
#define ARG_DRILL_ORIGIN "--drill-origin"
CLI::PCB_EXPORT_DRILL_COMMAND::PCB_EXPORT_DRILL_COMMAND() : PCB_EXPORT_BASE_COMMAND( "drill" )
CLI::PCB_EXPORT_DRILL_COMMAND::PCB_EXPORT_DRILL_COMMAND() : PCB_EXPORT_BASE_COMMAND( "drill", false, true )
{
m_argParser.add_description( UTF8STDSTR( _( "Generate Drill Files" ) ) );

View File

@ -39,7 +39,7 @@
CLI::SCH_ERC_COMMAND::SCH_ERC_COMMAND() : COMMAND( "erc" )
{
addCommonArgs( true, true, false );
addCommonArgs( true, true, false, false );
addDefineArg();
m_argParser.add_description( UTF8STDSTR( _( "Runs the Electrical Rules Check (ERC) on the schematic and creates a report" ) ) );

View File

@ -33,7 +33,7 @@
CLI::SCH_EXPORT_BOM_COMMAND::SCH_EXPORT_BOM_COMMAND() : COMMAND( "bom" )
{
m_argParser.add_description( UTF8STDSTR( _( "Generate a Bill of Material (BOM)" ) ) );
addCommonArgs( true, true, false );
addCommonArgs( true, true, false, false );
// Field output options
m_argParser.add_argument( ARG_FIELDS )

View File

@ -33,7 +33,7 @@
CLI::SCH_EXPORT_NETLIST_COMMAND::SCH_EXPORT_NETLIST_COMMAND() : COMMAND( "netlist" )
{
m_argParser.add_description( UTF8STDSTR( _( "Export a Netlist" ) ) );
addCommonArgs( true, true, false );
addCommonArgs( true, true, false, false );
m_argParser.add_argument( ARG_FORMAT )
.default_value( std::string( "kicadsexpr" ) )
@ -91,4 +91,4 @@ int CLI::SCH_EXPORT_NETLIST_COMMAND::doPerform( KIWAY& aKiway )
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, netJob.get() );
return exitCode;
}
}

View File

@ -50,7 +50,7 @@ CLI::SCH_EXPORT_PLOT_COMMAND::SCH_EXPORT_PLOT_COMMAND( const std::string& aName,
{
m_argParser.add_description( aDescription );
addCommonArgs( true, true, aOutputIsDir );
addCommonArgs( true, true, false, aOutputIsDir );
addDrawingSheetArg();
addDefineArg();
@ -151,4 +151,4 @@ int CLI::SCH_EXPORT_PLOT_COMMAND::doPerform( KIWAY& aKiway )
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, plotJob.get() );
return exitCode;
}
}

View File

@ -31,7 +31,7 @@
CLI::SCH_EXPORT_PYTHONBOM_COMMAND::SCH_EXPORT_PYTHONBOM_COMMAND() :
COMMAND( "python-bom" )
{
addCommonArgs( true, true, false );
addCommonArgs( true, true, false, false );
m_argParser.add_description( UTF8STDSTR( _( "Export the legacy bom xml format used in the "
"schematic editor with python scripts" ) ) );
@ -56,4 +56,4 @@ int CLI::SCH_EXPORT_PYTHONBOM_COMMAND::doPerform( KIWAY& aKiway )
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, bomJob.get() );
return exitCode;
}
}

View File

@ -36,7 +36,7 @@
CLI::SYM_EXPORT_SVG_COMMAND::SYM_EXPORT_SVG_COMMAND() : COMMAND( "svg" )
{
addCommonArgs( true, true, false );
addCommonArgs( true, true, false, true );
m_argParser.add_description( UTF8STDSTR( _( "Exports the symbol or entire symbol library to SVG" ) ) );

View File

@ -32,7 +32,7 @@
CLI::SYM_UPGRADE_COMMAND::SYM_UPGRADE_COMMAND() : COMMAND( "upgrade" )
{
addCommonArgs( true, true, false );
addCommonArgs( true, true, false, false );
m_argParser.add_description( UTF8STDSTR( _( "Upgrades the symbol library to the current kicad version format" ) ) );
@ -61,4 +61,4 @@ int CLI::SYM_UPGRADE_COMMAND::doPerform( KIWAY& aKiway )
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, symJob.get() );
return exitCode;
}
}