std::unique_ptr<CService> CService::FromExtension(CAddonInfo addonInfo, const cp_extension_t* ext) { START_OPTION startOption(START_OPTION::LOGIN); std::string start = CServiceBroker::GetAddonMgr().GetExtValue(ext->configuration, "@start"); if (start == "startup") startOption = START_OPTION::STARTUP; return std::unique_ptr<CService>(new CService(std::move(addonInfo), startOption)); }
void CLI::handleCommandLineArguments() { // lets support multiple cli options, each with different options // this should handle, e.g. "wpn-xm.exe --service nginx start" QCommandLineParser parser; /** * Definition of Command Line Arguments */ // -h, --help, -? QCommandLineOption helpOption(QStringList() << "h" << "help" << "?", "Prints this help message."); parser.addOption(helpOption); // -v, --version QCommandLineOption versionOption(QStringList() << "v" << "version", "Display the version."); parser.addOption(versionOption); // -s, --service // TODO: install / uninstall daemon as service from CLI (part1) //QCommandLineOption serviceOption(QStringList() << "s" << "service", "Install/Uninstall daemon as service.", "[daemon] [command]"); //parser.addOption(serviceOption); // -d, --daemon QCommandLineOption daemonOption(QStringList() << "d" << "daemon", "Execute a command on daemon.", "[daemon] [command]"); parser.addOption(daemonOption); // --start QCommandLineOption startOption("start", "Starts a daemon.", "[daemon/s]"); parser.addOption(startOption); // --stop QCommandLineOption stopOption("stop", "Stops a daemon.", "[daemon/s]"); parser.addOption(stopOption); // --restart QCommandLineOption restartOption("stop", "Restarts a daemon.", "[daemon/s]"); parser.addOption(restartOption); /** * Handling of Command Line Arguments */ // find out the positional arguments. parser.parse(QCoreApplication::arguments()); const QStringList args = parser.positionalArguments(); const QString command = args.isEmpty() ? QString() : args.first(); // -h, --help, -? if(parser.isSet(helpOption)) { printHelpText(); } // -v, --version if(parser.isSet(versionOption)) { colorPrint("WPN-XM Server Stack " APP_VERSION "\n", "brightwhite"); exit(0); } // -s, --service <daemon> <command>, where <command> is on|off //if (parser.isSet(serviceOption)) { // TODO: install / uninstall daemon as service from CLI (part2) // https://github.com/WPN-XM/WPN-XM/issues/39 //} // -d, --daemon <daemon> <command>, where <command> is start|stop|restart if (parser.isSet(daemonOption)) { // at this point we already have "--daemon <daemon>", but not <command>// // daemon is the value QString daemon = parser.value(daemonOption); if(daemon.isEmpty()) { printHelpText(QString("Error: no <daemon> specified.")); } Servers::Servers *servers = new Servers::Servers(); // check if daemon is whitelisted if(!servers->getListOfServerNames().contains(daemon)) { printHelpText( QString("Error: \"%1\" is not a valid <daemon>.") .arg(daemon.toLocal8Bit().constData()) ); } if(command.isEmpty()) { printHelpText(QString("Error: no <command> specified.")); } QStringList availableCommands = QStringList() << "start" << "stop" << "restart"; if(!availableCommands.contains(command)) { printHelpText( QString("Error: \"%1\" is not a valid <command>.") .arg(command.toLocal8Bit().constData()) ); } QString methodName = command + servers->getCamelCasedServerName(daemon); if(QMetaObject::invokeMethod(servers, methodName.toLocal8Bit().constData())) { exit(0); } printHelpText( QString("Command not handled, yet! (daemon = %1) (command = %2) \n") .arg(daemon.toLocal8Bit().constData(), command.toLocal8Bit().constData()) ); exit(0); } // --start <daemons> if (parser.isSet(startOption)) { execDaemons("start", startOption, args, parser); } // --stop <daemons> if (parser.isSet(stopOption)) { execDaemons("stop", stopOption, args, parser); } // --restart <daemons> if (parser.isSet(restartOption)) { execDaemons("stop", restartOption, args, parser); } //if(parser.unknownOptionNames().count() > 1) { printHelpText(QString("Error: Unknown option.")); //} }
cCommandLineInterface::cCommandLineInterface(QCoreApplication *qapplication) { // text from http://sourceforge.net/projects/mandelbulber/ parser.setApplicationDescription("Mandelbulber is an easy to use, " "handy application designed to help you render 3D Mandelbrot fractals called Mandelbulb " "and some other kind of 3D fractals like Mandelbox, Bulbbox, Juliabulb, Menger Sponge"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption noguiOption(QStringList() << "n" << "nogui", QCoreApplication::translate("main", "Start program without GUI.")); QCommandLineOption keyframeOption(QStringList() << "K" << "keyframe", QCoreApplication::translate("main", "Render keyframe animation")); QCommandLineOption flightOption(QStringList() << "F" << "flight", QCoreApplication::translate("main", "Render flight animation")); QCommandLineOption startOption(QStringList() << "s" << "start", QCoreApplication::translate("main", "Start rendering from frame number <N>."), QCoreApplication::translate("main", "N")); QCommandLineOption endOption(QStringList() << "e" << "end", QCoreApplication::translate("main", "Stop rendering on frame number <N>."), QCoreApplication::translate("main", "N")); QCommandLineOption overrideOption(QStringList() << "O" << "override", QCoreApplication::translate("main", "Override item '<KEY>' from settings file with new value '<value>'.\n" "Specify multiple KEY=VALUE pairs by separating with a '#' (KEY1=VALUE1#KEY2=VALUE2). Quote whole expression to avoid whitespace parsing issues\n" "Override fractal parameter in the form 'fractal<N>_KEY=VALUE' with <N> as index of fractal"), QCoreApplication::translate("main", "KEY=VALUE")); QCommandLineOption listOption(QStringList() << "L" << "list", QCoreApplication::translate("main", "List all possible parameters '<KEY>' with corresponding default value '<value>'.")); QCommandLineOption formatOption(QStringList() << "f" << "format", QCoreApplication::translate("main", "Image output format:\n" "jpg - JPEG format\n" "png - PNG format\n" "png16 - 16-bit PNG format\n" "png16alpha - 16-bit PNG with alpha channel format\n" "exr - EXR format"), QCoreApplication::translate("main", "FORMAT")); QCommandLineOption resOption(QStringList() << "r" << "res", QCoreApplication::translate("main", "Override image resolution."), QCoreApplication::translate("main", "WIDTHxHEIGHT")); QCommandLineOption fpkOption("fpk", QCoreApplication::translate("main", "Override frames per key parameter."), QCoreApplication::translate("main", "N")); QCommandLineOption serverOption(QStringList() << "S" << "server", QCoreApplication::translate("main", "Set application as a server listening for clients.")); QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set application as a client connected to server of given Host address" " (Host can be of type IPv4, IPv6 and Domain name address)."), QCoreApplication::translate("main", "N.N.N.N")); QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set network port number for Netrender (default 5555)."), QCoreApplication::translate("main", "N")); QCommandLineOption noColorOption(QStringList() << "C" << "no-cli-color", QCoreApplication::translate("main", "Start program without ANSI colors, when execution on CLI.")); QCommandLineOption outputOption(QStringList() << "o" << "output", QCoreApplication::translate("main", "Save rendered image(s) to this file / folder."), QCoreApplication::translate("main", "N")); QCommandLineOption queueOption(QStringList() << "q" << "queue", QCoreApplication::translate("main", "Render all images from common queue.")); QCommandLineOption statsOption(QStringList() << "stats", QCoreApplication::translate("main", "Show statistics while renderering in CLI mode.")); QCommandLineOption helpInputOption(QStringList() << "help-input", QCoreApplication::translate("main", "Show help about input.")); parser.addPositionalArgument("settings_file", QCoreApplication::translate("main", "file with fractal settings (program also tries\nto find file in ./mandelbulber/settings directory)\n" "When settings_file is put as a command line argument then program will start in noGUI mode" "<settings_file> can also be specified as a list, see all options with --help-input" )); parser.addOption(noguiOption); parser.addOption(outputOption); parser.addOption(keyframeOption); parser.addOption(flightOption); parser.addOption(startOption); parser.addOption(endOption); parser.addOption(overrideOption); parser.addOption(listOption); parser.addOption(formatOption); parser.addOption(resOption); parser.addOption(fpkOption); parser.addOption(serverOption); parser.addOption(hostOption); parser.addOption(portOption); parser.addOption(noColorOption); parser.addOption(queueOption); parser.addOption(statsOption); parser.addOption(helpInputOption); // Process the actual command line arguments given by the user parser.process(*qapplication); args = parser.positionalArguments(); cliData.nogui = parser.isSet(noguiOption); cliData.keyframe = parser.isSet(keyframeOption); cliData.flight = parser.isSet(flightOption); cliData.startFrameText = parser.value(startOption); cliData.endFrameText = parser.value(endOption); cliData.overrideParametersText = parser.value(overrideOption); cliData.imageFileFormat = parser.value(formatOption); cliData.resolution = parser.value(resOption); cliData.fpkText = parser.value(fpkOption); cliData.server = parser.isSet(serverOption); cliData.host = parser.value(hostOption); cliData.portText = parser.value(portOption); cliData.outputText = parser.value(outputOption); cliData.listParameters = parser.isSet(listOption); cliData.queue = parser.isSet(queueOption); cliData.showInputHelp = parser.isSet(helpInputOption); systemData.statsOnCLI = parser.isSet(statsOption); #ifdef WIN32 /* WINDOWS */ systemData.useColor = false; #else systemData.useColor = !parser.isSet(noColorOption); #endif /* WINDOWS */ if(cliData.listParameters) cliData.nogui = true; if(cliData.queue) cliData.nogui = true; cliTODO = modeBootOnly; }
int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); app.setOrganizationName("p10"); app.setApplicationName("sofia-eog-cli"); app.setApplicationVersion("0.0.1"); //==============Command line parser=========================== QCommandLineParser parser; parser.setApplicationDescription("Qt CLI frontend for the sofia-eog library"); parser.addHelpOption(); parser.addVersionOption(); // Records folder option QCommandLineOption recordsFolderOption(QStringList() << "r" << "records-folder", app.translate("main", "Set the records folder to <records-folder>."), app.translate("main", "records-folder")); parser.addOption(recordsFolderOption); // Filters folder option QCommandLineOption filtersFolderOption(QStringList() << "f" << "filters-folder", app.translate("main", "Set the filters folder to <filters-folder>."), app.translate("main", "filters-folder")); parser.addOption(filtersFolderOption); // Flush data files interval option QCommandLineOption flushDataFilesIntervalOption(QStringList() << "i" << "flush-interval", app.translate("main", "Set the interval to flush the buffer to file to <flush-interval> in seconds."), app.translate("main", "flush-interval")); parser.addOption(flushDataFilesIntervalOption); // Start recording option QCommandLineOption startOption(QStringList() << "s" << "start", app.translate("main", "Start recording.")); parser.addOption(startOption); // Restore default filters option QCommandLineOption restoreDefaultFiltersOption(QStringList() << "d" << "default-filters", app.translate("main", "Restore the default filters to the filters folder.")); parser.addOption(restoreDefaultFiltersOption); // Print all settings option QCommandLineOption printSettingsOption(QStringList() << "p" << "print-settings", app.translate("main", "Print the settings.")); parser.addOption(printSettingsOption); // Process the actual command line arguments given by the user parser.process(app); QString recordsFolder = parser.value(recordsFolderOption); QString filtersFolder = parser.value(filtersFolderOption); float flushDataFilesInterval = parser.value(flushDataFilesIntervalOption).toFloat(); QDir recordsDir(recordsFolder); QDir filtersDir(filtersFolder); //Create the folders if they're missing if( !recordsDir.exists() ){ if( !recordsDir.mkdir(recordsDir.absolutePath()) ){ qDebug()<<"Failed to create dir:"<<recordsFolder; return -1; } } if( !filtersDir.exists() ){ if( !filtersDir.mkdir(filtersDir.absolutePath()) ){ qDebug()<<"Failed to create dir:"<<filtersFolder; return -1; } } EOGLibrary lib(recordsFolder, filtersFolder); //Set the interval on which to flush the buffers to file if(lib.flushDataFilesInterval()!=flushDataFilesInterval){ lib.setFlushDataFilesInterval(flushDataFilesInterval); } //If the user wants to restore the default filters if(parser.isSet(restoreDefaultFiltersOption)){ lib.restoreDefaultFilterConfigurations(); } if(parser.isSet(printSettingsOption)){ qDebug()<<"Records folder:"<<lib.recordsFolder(); qDebug()<<"Default filters folder:"<<lib.defaultFiltersFolder(); qDebug()<<"Flush data file interval:"<<lib.flushDataFilesInterval(); //qDebug<<"Records folder:"<<lib.recordsFolder(); } //Initial info gathering //lib.updateAvailableInputDevices(); lib.updateDefaultFiltersList(); lib.updateRecordsList(); //Connections QObject::connect(&app,SIGNAL(aboutToQuit()),&lib,SLOT(stopRecording())); //Start recording if(parser.isSet(startOption)){ lib.startRecording(); }else{ app.processEvents(); app.exit(); } //Handle the CTRL+C signal (SIGINT) ap = &app; signal (SIGINT, handleInterruptSignal); //Start the event loop return app.exec(); }
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; }