Пример #1
19
int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    QCommandLineParser optionsParser;
    optionsParser.setApplicationDescription("Tool for generating pkg file for ministaller");
    ParsedOptions options;

    switch (parseCommandLine(optionsParser, app.arguments(), options)) {
    case CommandLineOk:
        break;
    case CommandLineError:
        std::cout << optionsParser.helpText().toStdString() << std::endl;
        return 1;
    case CommandLineHelpRequested:
        std::cout << optionsParser.helpText().toStdString() << std::endl;
        return 0;
    }

    DiffGenerator diffGenerator(options.m_BaseDir, options.m_NewDir);

    diffGenerator.generateDiffs();

    std::cout << "Done" << std::endl;

    auto json = diffGenerator.generateJson();

    if (!saveJson(options.m_JsonPath, json)) {
        if (!saveJson(DEFAULT_OUTPUT_NAME, json)) {
            std::cerr << "Failed to save json to file" << std::endl;
            return 1;
        }
    }

    return 0;
}
Пример #2
1
bool commandLineArgumentsValid(QStringList *positionalArgs,
                               QStringList *ignoreMasks)
{
  bool result = true;

  QCommandLineParser parser;
  parser.setApplicationDescription("Creates patches");
  parser.addHelpOption();
  parser.addVersionOption();
  parser.addPositionalArgument("old",     QCoreApplication::translate("main", "Path to a directory containing old version of files"));
  parser.addPositionalArgument("new",     QCoreApplication::translate("main", "Path to a directory containing new version of files"));
  parser.addPositionalArgument("result",  QCoreApplication::translate("main", "Path to a directory where resulting patch will be stored"));

  QCommandLineOption ignoreOption(QStringList() << "i" << "ignore",
                                  QCoreApplication::translate("main", "Specifies which file or folder to ignore during comparison. Can be used multiple times. e.g. -i .svn -i *.txt"),
                                  QCoreApplication::translate("main", "mask"));
  parser.addOption(ignoreOption);

  // Process the actual command line arguments given by the user
  parser.process(*qApp);

  *positionalArgs = parser.positionalArguments();
  if (positionalArgs->size() < 3)
  {
    fputs(qPrintable(parser.helpText()), stderr);
    result = false;
  }

  *ignoreMasks = parser.values(ignoreOption);

  return result;
}
Пример #3
0
int main(int argc, char ** argv)
{
    QUrl source("qrc:view.qml");

    QGuiApplication app(argc, argv);

    QCommandLineParser parser;
#if QT_CONFIG(networkproxy)
    QCommandLineOption proxyHostOption("host", "The proxy host to use.", "host");
    parser.addOption(proxyHostOption);
    QCommandLineOption proxyPortOption("port", "The proxy port to use.", "port", "0");
    parser.addOption(proxyPortOption);
#endif // networkproxy
    parser.addPositionalArgument("file", "The file to use.");
    QCommandLineOption helpOption = parser.addHelpOption();
    parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
    QStringList arguments = QCoreApplication::arguments();
    if (!parser.parse(arguments)) {
        qWarning() << parser.helpText() << '\n' << parser.errorText();
        exit(1);
    }
    if (parser.isSet(helpOption)) {
        qWarning() << parser.helpText();
        exit(0);
    }
#if QT_CONFIG(networkproxy)
    if (parser.isSet(proxyHostOption))
        proxyHost = parser.value(proxyHostOption);
    if (parser.isSet(proxyPortOption)) {
        bool ok = true;
        proxyPort = parser.value(proxyPortOption).toInt(&ok);
        if (!ok || proxyPort < 1 || proxyPort > 65535) {
            qWarning() << parser.helpText() << "\nNo valid port given. It should\
                          be a number between 1 and 65535";
            exit(1);
        }
    }
#endif // networkproxy
    if (parser.positionalArguments().count() == 1)
        source = QUrl::fromLocalFile(parser.positionalArguments().first());

    QQuickView view;
    view.engine()->setNetworkAccessManagerFactory(new MyNetworkAccessManagerFactory);

    view.setSource(source);
    view.show();

    return app.exec();
}
void tst_QCommandLineParser::testMultipleValuesOption()
{
    QCoreApplication app(empty_argc, empty_argv);
    QCommandLineOption option(QStringLiteral("param"), QStringLiteral("Pass parameter to the backend."));
    option.setValueName("key=value");
    QCommandLineParser parser;
    QVERIFY(parser.addOption(option));
    {
        QVERIFY(parser.parse(QStringList() << "tst" << "--param" << "key1=value1"));
        QVERIFY(parser.isSet("param"));
        QCOMPARE(parser.values("param"), QStringList() << "key1=value1");
        QCOMPARE(parser.value("param"), QString("key1=value1"));
    }
    {
        QVERIFY(parser.parse(QStringList() << "tst" << "--param" << "key1=value1" << "--param" << "key2=value2"));
        QVERIFY(parser.isSet("param"));
        QCOMPARE(parser.values("param"), QStringList() << "key1=value1" << "key2=value2");
        QCOMPARE(parser.value("param"), QString("key2=value2"));
    }

    QString expected =
        "Usage: tst_qcommandlineparser [options]\n"
        "\n"
        "Options:\n"
        "  --param <key=value>  Pass parameter to the backend.\n";

    const QString exeName = QCoreApplication::instance()->arguments().first(); // e.g. debug\tst_qcommandlineparser.exe on Windows
    expected.replace(QStringLiteral("tst_qcommandlineparser"), exeName);
    QCOMPARE(parser.helpText(), expected);
}
Пример #5
0
int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

//! [1]
    QCoreApplication::setApplicationVersion(QT_VERSION_STR);
    QCoreApplication::setApplicationName(QCoreApplication::translate("QDnsLookupExample", "DNS Lookup Example"));
    QCommandLineParser parser;
    parser.setApplicationDescription(QCoreApplication::translate("QDnsLookupExample", "An example demonstrating the class QDnsLookup."));
    DnsQuery query;
    QString errorMessage;
    switch (parseCommandLine(parser, &query, &errorMessage)) {
    case CommandLineOk:
        break;
    case CommandLineError:
        fputs(qPrintable(errorMessage), stderr);
        fputs("\n\n", stderr);
        fputs(qPrintable(parser.helpText()), stderr);
        return 1;
    case CommandLineVersionRequested:
        printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
               qPrintable(QCoreApplication::applicationVersion()));
        return 0;
    case CommandLineHelpRequested:
        parser.showHelp();
        Q_UNREACHABLE();
    }
//! [1]

    DnsManager manager;
    manager.setQuery(query);
    QTimer::singleShot(0, &manager, SLOT(execute()));

    return app.exec();
}
Пример #6
0
static void showHelp(QCommandLineParser &parser, const QString errorMessage = QString())
{
    QString text;
    QTextStream str(&text);
    str << "<html><head/><body>";
    if (!errorMessage.isEmpty())
        str << "<p>" << errorMessage << "</p>";
    str << "<pre>" << parser.helpText() << "</pre></body></html>";
    QMessageBox box(errorMessage.isEmpty() ? QMessageBox::Information : QMessageBox::Warning,
        QGuiApplication::applicationDisplayName(), text, QMessageBox::Ok);
    box.setTextInteractionFlags(Qt::TextBrowserInteraction);
    box.exec();
}
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QCoreApplication::setApplicationName(a.translate("main", "OrgModeParser clock time summary"));
    QCoreApplication::setApplicationVersion(OrgMode::version());
    QCommandLineParser parser;
    try {
        parser.setApplicationDescription(a.translate("main", "Clock time summary tool, part of OrgModeParser."));
        parser.addHelpOption();
        parser.addVersionOption();
        QCommandLineOption columnsOption(QStringList() << QStringLiteral("c") << QStringLiteral("columns"),
                                         a.translate("main", "Terminal columns."),
                                         a.translate("main", "columns"));
        QCommandLineOption promptModeOption(QStringList() << QStringLiteral("p") << QStringLiteral("promptmode"),
                                            a.translate("main", "Prompt mode (no newline at end)."));
        parser.addOption(columnsOption);
        parser.addOption(promptModeOption);
        parser.process(a);
        int columns;
        if (parser.isSet(columnsOption)) {
            bool ok;
            columns = parser.value(columnsOption).toInt(&ok);
            if (!ok) {
                throw RuntimeException(a.translate("main", "Columns argument needs to be an integer number!"));
            }
        } else {
            columns = 60;
        }
        const bool promptMode = parser.isSet(promptModeOption);
        ClockTimeSummary clocktime(parser.positionalArguments());
        clocktime.report(promptMode, columns);
    } catch (const RuntimeException& ex) {
        wcerr << "Error: " << ex.message().toStdWString() << endl
              << parser.helpText().toStdWString() << endl;
    }
}
Пример #8
0
int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    QCoreApplication::setApplicationName("Impedance");
    QCoreApplication::setApplicationVersion("1.0");
    QCommandLineParser parser;
    parser.setApplicationDescription("Automated electrode impedance testing and activation using RHD2000 chips.");

    CLOptions options;
    QString errorMessage;
    switch (parseCommandLine(parser, &options, &errorMessage)) {
    case CommandLineOk:
        break;
    case CommandLineError:
        fputs(qPrintable(errorMessage), stderr);
        fputs("\n\n", stderr);
        fputs(qPrintable(parser.helpText()), stderr);
        return 1;
    case CommandLineVersionRequested:
        printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
               qPrintable(QCoreApplication::applicationVersion()));
        return 0;
    case CommandLineHelpRequested:
        parser.showHelp();
        Q_UNREACHABLE();
    }

    // TODO: The headstage selection and port selection is currently hardcoded
    // and screwed up.
    // e.g
    // Handle 2X32 chan headstages
    // handle multiple ports
    // handle 64 chan headstages.
    PlateControl *plateControl = new PlateControl(options.currentGain);
    AutoImpedance *autoImpedance = new AutoImpedance(350.0e3, 100.0 * 50.0e3/350.0e3, 5);
    ImpedanceLog *logger = new ImpedanceLog(options.fid);
    RHD2000Impedance *impedance = new RHD2000Impedance(Rhd2000EvalBoard::PortA, logger);

    impedance->configurePlate(plateControl);
    plateControl->setHeadstage(0);

    int ch, mode;
    impedance->setImpedanceTestFrequency(1000);


    while(true) {

        cout << endl;
        cout << "Select an action:" << endl;
        cout << "   [1]: Single channel impedance test." << endl;
        cout << "   [2]: Single channel plate. " << endl;
        cout << "   [3]: Single channel electrode clean. " << endl;
        cout << "   [4]: All channel impedance check. "  << endl;
        cout << "   [5]: All channel plate."  << endl;
        cout << "   [6]: All channel electrode clean."  << endl;
        cout << "   [7]: Automated impedance test and electrode activation." << endl;
        cout << "   [8]: Change impedance test and plating parameters." << endl;
        cout << "   [9]: Change log save location." << endl;
        cout << "   [10]: Clear log." << endl;
        cout << "   [11]: Exit without saving." << endl;
        cout << "   [12]: Save log and exit program." << endl;
        cin >> mode;

        switch(mode) {

        case 1:

            cout << "Select a channel." << endl;
            cin >> ch;
            impedance->setChannel(ch);
            impedance->measureImpedance(logger);
            impedance->printImpedance();
            break;

        case 2:

            cout << "Select a channel." << endl;
            cin >> ch;
            impedance->setChannel(ch);
            impedance->plate(plateControl, logger);
            break;

        case 3:

            cout << "Select a channel." << endl;
            cin >> ch;
            impedance->setChannel(ch);
            impedance->clean(plateControl, logger);
            break;

        case 4:

            // TODO: Fix hardcoded number of channels, ports,etc
            for (int ch=0; ch < 32; ch++) {

                impedance->setChannel(ch);
                impedance->measureImpedance(logger);
                impedance->printImpedance();
            }
            break;

        case 5:

            // TODO: Fix hardcoded number of channels, ports,etc
            for (int ch=0; ch < 32; ch++) {

                impedance->setChannel(ch);
                impedance->plate(plateControl, logger);
            }
            break;

        case 6:

            // TODO: Fix hardcoded number of channels, ports,etc
            for (int ch=0; ch < 32; ch++) {

                impedance->setChannel(ch);
                impedance->clean(plateControl, logger);
            }
            break;

        case 7:
        {
            cout << "Select a channel." << endl;
            cin >> ch;
            impedance->setChannel(ch);
            autoImpedance->autoPlate(impedance, plateControl, logger);

            break;
        }
        case 8:
        {
            bool exitParamsDialog = false;
            do {

                int parameter;
                cout << endl;
                cout << "Select parameter to modify:" << endl;
                cout << "   [1]: Test frequency." << endl;
                cout << "   [2]: Number of averages. " << endl;
                cout << "   [3]: Number of test periods. "  << endl;
                cout << "   [4]: Change plate duration." << endl;
                cout << "   [5]: Change plate current." << endl;
                cout << "   [6]: Change cleaning duration." << endl;
                cout << "   [7]: Change cleaning current." << endl;
                cout << "   [10]: Exit to main menu." << endl;
                cin >> parameter;

                switch(parameter) {

                case 1:
                {
                    double freq;
                    cout << "Enter an impedance test frequency (Hz)." << endl;
                    cin >> freq;
                    impedance->setImpedanceTestFrequency(freq);

                    break;
                }

                case 2:
                {
                    int na;
                    cout << "Enter a number of aveages for each impedance measurement." << endl;
                    cin >> na;
                    impedance->setNumAverages(na);

                    break;
                }

                case 3:
                {
                    int np;
                    cout << "Enter a number of test waveform periods for each measurement." << endl;
                    cin >> np;
                    impedance->setNumPeriods(np);

                    break;
                }

                case 4:
                {
                    int pd;
                    cout << "Enter a new plating duration (msec)." << endl;
                    cin >> pd;
                    plateControl->setPlateDuration(pd);

                    break;
                }

                case 5:
                {
                    int pc;
                    cout << "Enter a new plating current (uA)." << endl;
                    cin >> pc;
                    plateControl->setPlateCurrent(pc);

                    break;
                }

                case 6:
                {
                    int ct;
                    cout << "Enter a new cleaning duration (msec)." << endl;
                    cin >> ct;
                    plateControl->setCleaningDuration(ct);

                    break;
                }

                case 7:
                {
                    int cc;
                    cout << "Enter a new cleaning current (uA)" << endl;
                    cin >> cc;
                    plateControl->setCleaningCurrent(cc);

                    break;
                }

                case 10:
                {
                    exitParamsDialog = true;
                    break;
                }


                default:


                    cout << "Invalid parameter selection. Try again." << endl;
                    break;
                }
            } while(!exitParamsDialog);

            break;
        }
        case 9:
        {
            string fn;
            cout << "Enter a new file name." << endl;
            cin >> fn;
            QString fid = QString::fromStdString(fn);
            logger->setSaveLocation(fid, false);

            break;
        }
        case 10:
        {
            logger->clearLogFile(impedance);
            break;
        }

        case 11:

            return 0;

            break;

        case 12:
            if(logger->saveLog())
                return 0;
            else
                cout << "Something went wrong while trying to save the log." << endl;
            cout << "You can specify a new save location in the main menu." << endl;

            break;

        default:
            cout << "Invalid mode selection. Try again." << endl;
            break;
        }
    }
}
Пример #9
0
int main(int argc, char *argv[]){
    QTime t;
    t.start();
    //START APP
    QApplication app(argc,argv);
    app.setWindowIcon(QIcon(":/data/img/11412394_407750046078820_6932822019341529347_n.jpg"));
    QApplication::setApplicationName("Huffman");
    QApplication::setApplicationVersion("ÚNICO");
    QQmlApplicationEngine engine;
    QQmlContext *interpreter = engine.rootContext();
    Huffman huff;
    DHuffman deHuff;
    QCommandLineParser parser;
    //Parser
    parser.addHelpOption();
    parser.addVersionOption();
    parser.setApplicationDescription("Huffman Parsers");
    parser.addPositionalArgument("in-file.x", QCoreApplication::translate("main", "File being compressed."));
    parser.addPositionalArgument("out-name.huff", QCoreApplication::translate("main", "Name to save archive."));
    //parser.addPositionalArgument("dir", QCoreApplication::translate("main", "Dir being compressed"));
    parser.addPositionalArgument("local", QCoreApplication::translate("main", "Local to save archive."));
    QCommandLineOption compress("c",QApplication::translate("main","Compress <in-file.x>."),
                                QApplication::translate("main","in-file.x"));
    parser.addOption(compress);
    QCommandLineOption outName("o",QApplication::translate("main","Save as <out-name.huff>."),
                               QApplication::translate("main","out-file.huff"));
    parser.addOption(outName);
    QCommandLineOption local("d",QApplication::translate("main","Decompress in <local>."),
                             QApplication::translate("main","local"));
    parser.addOption(local);
    QCommandLineOption startGui({"g", "gui"},QApplication::translate("main","Start gui."));
    parser.addOption(startGui);
    parser.process(app);

    //ARGUMENTS
    if(parser.isSet(startGui)){
        interpreter->setContextProperty("_huff",&huff);
        interpreter->setContextProperty("_dehuff",&deHuff);
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    }
    else if(parser.isSet(compress) && parser.isSet(outName))
    {
        cout << "case 1" << endl;
        huff.Huff(parser.value(compress),parser.value(outName));
    }
    else if(parser.isSet(compress))
    {
        cout << "case 2" << endl;
        huff.Huff(parser.value(compress),parser.value(compress));
    }
    else{
        if(app.arguments().size() == 1)
            qDebug() << qPrintable(parser.helpText());
        else if(parser.isSet(local))
            deHuff.DHuff(app.arguments().at(1),parser.value(local));
        else
            deHuff.DHuff(app.arguments().at(1),app.arguments().at(1));
    }
    //END APP
    qDebug("%s <> Tempo de execução: %d ms",Q_FUNC_INFO,t.elapsed());
    return app.exec();
}
Пример #10
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
	
	QCommandLineParser parser;
    parser.addHelpOption();
    parser.addPositionalArgument("file", QCoreApplication::translate("main", "The file to open."));
    parser.addOptions({
        { { "c", "curve" }, QString("Extract a curve.") },
        { { "s", "sheet" }, QString("Extract a sheet.") },
        { { "b", "box" }, QString("Uses bounding box.") },
		{ { "n", "nonmanifold" }, QString("Object is not clean.") },
		{ { "h", "concavehull" }, QString("Reconstruct using concavehull.") },
		{ { "v", "voxelize" }, QString("Reconstruct using voxels.") },
		{ { "r", "remesh" }, QString("Remesh to increase density.") },
		{ { "m", "medial" }, QString("Follow medial axis during skeletonization.") },
		{ { "f", "features" }, QString("Respect small features.") },
		{ { "V", "voxelparam" }, QString("Voxels size."), QString("voxel_param") },
		{ { "R", "remeshparam" }, QString("Remesh size."), QString("remesh_param") }
    });

	if (!parser.parse(QCoreApplication::arguments())) {
        QString errorText = parser.errorText();
        std::cout << qPrintable(errorText);
        return CommandLineError;
    }
	else
		parser.process(a);

    if(QCoreApplication::arguments().size() == 1)
    {
        std::cout << qPrintable(parser.helpText());
        return CommandLineHelpRequested;
    }

    // Perform operations
    {
		double VoxelParam = 0.05, RemeshParam = 0.02;

		if (parser.isSet("voxelparam")) VoxelParam = parser.value("voxelparam").toDouble();
		if (parser.isSet("remeshparam")) RemeshParam = parser.value("remeshparam").toDouble();

        QString filename = parser.positionalArguments().at(0);
        nurbs_plugin plugin(filename, !parser.isSet("nonmanifold"), 
			parser.isSet("b"), parser.isSet("h"), parser.isSet("v"), 
			parser.isSet("r"), parser.isSet("m"), parser.isSet("f"),
			VoxelParam, RemeshParam);

		if (parser.isSet("curve"))
		{
			auto c = plugin.toCurve();

			// Save control points
			QFile file("curve_output.points");
			if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return CommandLineError;
			QTextStream out(&file);
			out << QString("%1\n").arg(c.GetNumCtrlPoints());
			for (auto p : c.mCtrlPoint) out << QString("%1 %2 %3\n").arg(p.x()).arg(p.y()).arg(p.z());
		}

		if (parser.isSet("sheet"))
		{
			auto s = plugin.toSheet();

			// Save control points
			QFile file("sheet_output.points");
			if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return CommandLineError;
			QTextStream out(&file);
			out << QString("%1\n").arg(s.mNumUCtrlPoints);
			out << QString("%1\n").arg(s.mNumVCtrlPoints);
			for (auto row : s.mCtrlPoint) 
				for (auto p : row)
					out << QString("%1 %2 %3\n").arg(p.x()).arg(p.y()).arg(p.z());
		}
    }

    return CommandLineOk;
}