[calamares] Refactor argument-handling
- Move parameter handling out of main - Give -D an argument (log level)
This commit is contained in:
parent
a1cbb161ee
commit
de1710a9f3
@ -35,6 +35,45 @@
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
static void
|
||||
handle_args( CalamaresApplication& a )
|
||||
{
|
||||
QCommandLineOption debugOption( QStringList{ "d", "debug"},
|
||||
"Also look in current directory for configuration. Implies -D8." );
|
||||
QCommandLineOption debugLevelOption( QStringLiteral("D"),
|
||||
"Verbose output for debugging purposes (0-8).", "level" );
|
||||
QCommandLineOption configOption( QStringList{ "c", "config"},
|
||||
"Configuration directory to use, for testing purposes.", "config" );
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription( "Distribution-independent installer framework" );
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
|
||||
parser.addOption( debugOption );
|
||||
parser.addOption( debugLevelOption );
|
||||
parser.addOption( configOption );
|
||||
|
||||
parser.process( a );
|
||||
|
||||
a.setDebug( parser.isSet( debugOption ) );
|
||||
if ( parser.isSet( debugOption ) )
|
||||
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
||||
else if ( parser.isSet( debugLevelOption ) )
|
||||
{
|
||||
bool ok = true;
|
||||
int l = parser.value( debugLevelOption ).toInt( &ok );
|
||||
unsigned int dlevel = 0;
|
||||
if ( !ok || ( l < 0 ) )
|
||||
dlevel = Logger::LOGVERBOSE;
|
||||
else
|
||||
dlevel = l;
|
||||
Logger::setupLogLevel( dlevel );
|
||||
}
|
||||
if ( parser.isSet( configOption ) )
|
||||
CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) );
|
||||
}
|
||||
|
||||
int
|
||||
main( int argc, char* argv[] )
|
||||
{
|
||||
@ -59,28 +98,7 @@ main( int argc, char* argv[] )
|
||||
a.setApplicationDisplayName( QString() );
|
||||
#endif
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription( "Distribution-independent installer framework" );
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
QCommandLineOption debugOption( QStringList{ "d", "debug"},
|
||||
"Also look in current directory for configuration. Implies -D." );
|
||||
parser.addOption( debugOption );
|
||||
|
||||
parser.addOption( QCommandLineOption( QStringLiteral("D"),
|
||||
"Verbose output for debugging purposes." ) );
|
||||
|
||||
QCommandLineOption configOption( QStringList{ "c", "config"},
|
||||
"Configuration directory to use, for testing purposes.", "config" );
|
||||
parser.addOption( configOption );
|
||||
|
||||
parser.process( a );
|
||||
|
||||
a.setDebug( parser.isSet( debugOption ) );
|
||||
|
||||
if ( parser.isSet( configOption ) )
|
||||
CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) );
|
||||
|
||||
handle_args( a );
|
||||
KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances );
|
||||
|
||||
int returnCode = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user