void parseCommandLine(QCoreApplication &app, CmdLineOptions *opts) { QCommandLineParser parser; parser.setApplicationDescription("remove db key at specified path"); parser.addHelpOption(); parser.addVersionOption(); parser.addPositionalArgument("key", QCoreApplication::translate("main", "key")); QCommandLineOption debugOption(QStringList() << "d" << "debug", QCoreApplication::translate("main", "enable debug/verbose logging")); parser.addOption(debugOption); parser.process(app); opts->debuggingEnabled = parser.isSet(debugOption); const QStringList posArgs = parser.positionalArguments(); if (posArgs.size() < 1) { qCritical("invalid arguments"); exit(1); } opts->key = posArgs.at(0); DbdLogging::logger()->debugMode = opts->debuggingEnabled; qDebug() << "debugging enabled:" << opts->debuggingEnabled; qDebug() << "key:" << opts->key; }
int main( int argc, char* argv[] ) { CalamaresApplication a( argc, argv ); QCommandLineParser parser; parser.setApplicationDescription( "Distribution-independent installer framework" ); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption debugOption( QStringList() << "d" << "debug", "Verbose output for debugging purposes." ); parser.addOption( debugOption ); 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 ) ) ); KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); int returnCode = 0; if ( guard.isPrimaryInstance() ) { a.init(); returnCode = a.exec(); } else qDebug() << "Calamares is already running, shutting down."; return returnCode; }
QT_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QCommandLineParser parser; parser.setApplicationDescription(QLatin1String("winrtrunner installs, runs, and collects test " "results for packages made with Qt.")); parser.addPositionalArgument(QStringLiteral("package [arguments]"), QLatin1String("The executable or package manifest to act upon. " "Arguments after the package name will be passed " "to the application when it starts.")); QCommandLineOption testOption(QStringLiteral("test"), QLatin1String("Install, start, collect output, stop (if needed), " "and uninstall the package. This is the " "default action of winrtrunner.")); parser.addOption(testOption); QCommandLineOption startOption(QStringLiteral("start"), QLatin1String("Start the package. The package is installed if " "it is not already installed. Pass --install to " "force reinstallation.")); parser.addOption(startOption); QCommandLineOption debugOption(QStringLiteral("debug"), QLatin1String("Start the package with the debugger attached. " "The package is installed if it is not already " "installed. Pass --install to force " "reinstallation."), QLatin1Literal("debugger")); parser.addOption(debugOption); QCommandLineOption debuggerArgumentsOption(QStringLiteral("debugger-arguments"), QLatin1String("Arguments that are passed to the " "debugger when --debug is used. If no " "debugger was provided this option is " "ignored."), QLatin1String("arguments")); parser.addOption(debuggerArgumentsOption); QCommandLineOption suspendOption(QStringLiteral("suspend"), QLatin1String("Suspend a running package. When combined " "with --stop or --test, the app will be " "suspended before being terminated.")); parser.addOption(suspendOption); QCommandLineOption stopOption(QStringLiteral("stop"), QLatin1String("Terminate a running package. Can be be " "combined with --start and --suspend.")); parser.addOption(stopOption); QCommandLineOption waitOption(QStringLiteral("wait"), QLatin1String("If the package is running, waits the given " "number of seconds before continuing to the next " "task. Passing 0 causes the runner to wait " "indefinitely."), QStringLiteral("seconds")); parser.addOption(waitOption); QCommandLineOption installOption(QStringLiteral("install"), QStringLiteral("(Re)installs the package.")); parser.addOption(installOption); QCommandLineOption removeOption(QStringLiteral("remove"), QStringLiteral("Uninstalls the package.")); parser.addOption(removeOption); QCommandLineOption deviceOption(QStringLiteral("device"), QLatin1String("Specifies the device to target as a device name " " or index. Use --list-devices to find available " "devices. The default device is the first device " "found for the active run profile."), QStringLiteral("name|index")); parser.addOption(deviceOption); QCommandLineOption profileOption(QStringLiteral("profile"), QStringLiteral("Force a particular run profile."), QStringLiteral("name")); parser.addOption(profileOption); QCommandLineOption listDevicesOption(QStringLiteral("list-devices"), QLatin1String("List the available devices " "(for use with --device).")); parser.addOption(listDevicesOption); QCommandLineOption verbosityOption(QStringLiteral("verbose"), QLatin1String("The verbosity level of the message output " "(0 - silent, 1 - info, 2 - debug). Defaults to 1."), QStringLiteral("level"), QStringLiteral("1")); parser.addOption(verbosityOption); QCommandLineOption ignoreErrorsOption(QStringLiteral("ignore-errors"), QStringLiteral("Always exit with code 0, regardless of the error state.")); parser.addOption(ignoreErrorsOption); parser.addHelpOption(); parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); QStringList arguments = QCoreApplication::arguments(); parser.parse(arguments); QStringList filterRules = QStringList() // Default logging rules << QStringLiteral("qt.winrtrunner.warning=true") << QStringLiteral("qt.winrtrunner.critical=true") << QStringLiteral("qt.winrtrunner.app=true"); if (parser.isSet(verbosityOption)) { bool ok; uint verbosity = parser.value(verbosityOption).toUInt(&ok); if (!ok || verbosity > 2) { qCCritical(lcWinRtRunner) << "Incorrect value specified for verbosity."; parser.showHelp(1); } switch (verbosity) { case 2: // Enable debug print filterRules.append(QStringLiteral("qt.winrtrunner.debug=true")); break; case 1: // Remove warnings filterRules.removeFirst(); // fall through case 0: // Silent filterRules.removeFirst(); // fall through default: // Impossible break; } } QLoggingCategory::setFilterRules(filterRules.join(QLatin1Char('\n'))); if (parser.isSet(listDevicesOption)) { std::wcout << "Available devices:\n"; const QMap<QString, QStringList> deviceNames = Runner::deviceNames(); foreach (const QString &profile, deviceNames.keys()) { std::wcout << reinterpret_cast<const wchar_t *>(profile.utf16()) << ":\n"; int index = 0; foreach (const QString &device, deviceNames.value(profile)) { std::wcout << " " << index++ << ' ' << reinterpret_cast<const wchar_t *>(device.utf16()) << '\n'; } } std::wcout << std::endl; return 0; }