Migration of QtMvvm from github
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.6 KiB

#include <QCoreApplication>
#include <QCommandLineParser>
#include <QFile>
#include <QXmlStreamReader>
#include <QDebug>
#include "cppsettingsgenerator.h"
#include "qmlsettingsgenerator.h"
#include "settingstranslator.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName(QStringLiteral(TARGET));
QCoreApplication::setApplicationVersion(QStringLiteral(VERSION));
QCoreApplication::setOrganizationName(QStringLiteral(COMPANY));
QCoreApplication::setOrganizationDomain(QStringLiteral(BUNDLE_PREFIX));
QCommandLineParser parser;
parser.setApplicationDescription(QStringLiteral("A tool to...")); //TODO description
parser.addVersionOption();
parser.addHelpOption();
parser.addOption({
{QStringLiteral("tr"), QStringLiteral("translate")},
QStringLiteral("Translate the given settings file. The output will be"
"a dummy cpp file, writte to --impl.")
});
parser.addOption({
QStringLiteral("qml"),
QStringLiteral("Generate the QML-bindings for the given settings xml "
"instead of the default cpp bindings.")
});
parser.addOption({
QStringLiteral("in"),
QStringLiteral("The input XML <file> containing the settings definition"),
QStringLiteral("file")
});
parser.addOption({
QStringLiteral("header"),
QStringLiteral("The <name> of the header file to generate"),
QStringLiteral("name")
});
parser.addOption({
QStringLiteral("impl"),
QStringLiteral("The <name> of the implementation file to generate"),
QStringLiteral("name")
});
parser.process(a);
if(parser.isSet(QStringLiteral("translate"))) {
try {
SettingsTranslator translator {parser.value(QStringLiteral("impl"))};
translator.process(parser.value(QStringLiteral("in")));
return EXIT_SUCCESS;
} catch (SettingsTranslator::Exception &e) {
qCritical() << e.what();
return EXIT_FAILURE;
}
} else if(parser.isSet(QStringLiteral("qml"))) {
try {
QmlSettingsGenerator generator {
parser.value(QStringLiteral("header")),
parser.value(QStringLiteral("impl"))
};
generator.process(parser.value(QStringLiteral("in")));
return EXIT_SUCCESS;
} catch (SettingsGeneratorImpl::Exception &e) {
qCritical() << e.what();
return EXIT_FAILURE;
}
} else {
try {
CppSettingsGenerator generator {
parser.value(QStringLiteral("header")),
parser.value(QStringLiteral("impl"))
};
generator.process(parser.value(QStringLiteral("in")));
return EXIT_SUCCESS;
} catch (SettingsGeneratorImpl::Exception &e) {
qCritical() << e.what();
return EXIT_FAILURE;
}
}
}