Skip to content

Commit

Permalink
Abort if mandatory parameters aren't specified
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 15, 2020
1 parent bbf7dfb commit 3d1d699
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/process/qgsprocess.cpp
Expand Up @@ -245,7 +245,7 @@ void QgsProcessingExec::showUsage( const QString &appName )
<< "\tplugins\tlist available and active plugins\n"
<< "\tlist\tlist all available processing algorithms\n"
<< "\thelp\tshow help for an algorithm. The algorithm id argument must be specified.\n"
<< "\trun\truns an algorithm. The algorithm id argument and parameter values must be specified.\n";
<< "\trun\truns an algorithm. The algorithm id argument and parameter values must be specified. Parameter values are specified via the --PARAMETER=VALUE syntax\n";

std::cout << msg.join( QString() ).toLocal8Bit().constData();
}
Expand Down Expand Up @@ -396,6 +396,27 @@ int QgsProcessingExec::execute( const QString &id, const QVariantMap &params )
std::cout << it.key().toLocal8Bit().constData() << ":\t" << it.value().toString().toLocal8Bit().constData() << '\n';
}

const QgsProcessingParameterDefinitions defs = alg->parameterDefinitions();
QList< const QgsProcessingParameterDefinition * > missingParams;
for ( const QgsProcessingParameterDefinition *p : defs )
{
if ( !( p->flags() & QgsProcessingParameterDefinition::FlagOptional ) && !params.contains( p->name() ) )
{
missingParams << p;
}
}

if ( !missingParams.isEmpty() )
{
std::cerr << QStringLiteral( "ERROR: The following mandatory parameters were not specified\n\n" ).toLocal8Bit().constData();
for ( const QgsProcessingParameterDefinition *p : qgis::as_const( missingParams ) )
{
std::cerr << QStringLiteral( "\t%1:\t%2\n" ).arg( p->name(), p->description() ).toLocal8Bit().constData();
}

return 1;
}

QgsProcessingContext context;
ConsoleFeedback feedback;

Expand Down

0 comments on commit 3d1d699

Please sign in to comment.