/*
* $Id$
*
* Copyright (C) 2013 Wilhelm Meier (wilhelm.meier@fh-kl.de)
*
* This file is part of app, the asciidoc-preprocessor.
*
* asciidoc-preprocessor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* asciidoc-preprocessor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with asciidoc-preprocessor. If not, see
* <http://www.gnu.org/licenses/>.
*/
#define NO_LOCAL_QDEBUG
#include "global.h"
#include <QApplication>
#include <QTimer>
#include <QTextStream>
#include <QIODevice>
#include <QDebug>
#if (QT_VERSION >= QT_VERSION_CHECK(5,2,0))
# include "util/commandlineparser.h"
# include <QCommandLineParser>
# include <QCommandLineOption>
#endif
#include "logging/basicstdloggerengine.h"
#include "application.h"
#include "asciidoc/asciidoc.h"
namespace {
static const char ORGANIZATION_NAME[] = "mbm-it";
static const char ORGANIZATION_DOMAIN[] = "mbm-it.de";
static const char APPLICATION_NAME[] = "asciidoc_preprocessor";
static const char APPLICATION_VERSION[] = "0.1";
}
int main(int argc, char** argv) {
QApplication a(argc, argv);
for(const auto e: qxtLog->allLoggerEngines()) {
QxtLoggerEngine* engine = qxtLog->takeLoggerEngine(e);
delete engine;
}
qxtLog->setMinimumLevel(QxtLogger::TraceLevel);
qxtLog->addLoggerEngine("stdout", new BasicSTDLoggerEngine);
qxtLog->setMinimumLevel(QxtLogger::InfoLevel);
// NOTE: keep all these options in sync with aedit
CommandLineParser cliParser;
cliParser.setApplicationDescription(notr(APPLICATION_NAME));
cliParser.addHelpOption();
cliParser.addVersionOption();
// Positional arguments
cliParser.addPositionalArgument("file", QObject::tr("File to process"));
// boolean arguments
QCommandLineOption qtHelpOption("qt-help", "show QT options");
cliParser.addOption(qtHelpOption);
QCommandLineOption debugOption(QStringList() << "d" << "debug", QObject::tr("Display debug information"));
cliParser.addOption(debugOption);
QCommandLineOption traceOption(QStringList() << "t" << "trace", QObject::tr("Print trace information"));
cliParser.addOption(traceOption);
QCommandLineOption loggingOption(QStringList() << "l" << "logging", QObject::tr("Enable logging to file"));
cliParser.addOption(loggingOption);
QCommandLineOption markerOption(QStringList() << "m" << "marker", QObject::tr("Enable marker generation"));
cliParser.addOption(markerOption);
QCommandLineOption tempObjectsOption(QStringList() << "y" << "tempobjects",
QObject::tr("Don't remove temporäry objects (from built-in filters, eg. plantum, blockdiag"));
cliParser.addOption(tempObjectsOption);
QCommandLineOption relPathsOption(QStringList() << "relativePaths",
QObject::tr("Use relative paths for generated objects"));
cliParser.addOption(relPathsOption);
QCommandLineOption dependencyOption(QStringList() << "M" << "depend",
QObject::tr("generate a dpendency list for inclusion into make files"));
cliParser.addOption(dependencyOption);
QCommandLineOption preprocessOnlyOption(QStringList() << "E" << "preprocessOnly",
QObject::tr("only do the preprocess step, don't call asciidoc"));
cliParser.addOption(preprocessOnlyOption);
QCommandLineOption urlcheckOption(QStringList() << "u" << "nourlcheck",
QObject::tr("don't check urls"));
cliParser.addOption(urlcheckOption);
// value arguments
QCommandLineOption docbaseOption(Asciidoc::OPTION_DOCBASE,
QObject::tr("Base url for doc inline macro"),
QString("docbase"),
QString("http://docs.oracle.com/javase/7/docs/api"));
cliParser.addOption(docbaseOption);
QCommandLineOption docsuffixOption(Asciidoc::OPTION_DOCSUFFIX,
QObject::tr("Default suffix for doc inline macro"),
Asciidoc::OPTION_DOCSUFFIX,
QString(".html"));
cliParser.addOption(docsuffixOption);
QCommandLineOption javapkgOption(Asciidoc::OPTION_JAVAPKG,
QObject::tr("Default Java package"),
Asciidoc::OPTION_JAVAPKG,
QString("java/lang"));
cliParser.addOption(javapkgOption);
QCommandLineOption srcbaseOption(Asciidoc::OPTION_SRCBASE,
QObject::tr("Base path for source macro"),
Asciidoc::OPTION_SRCBASE,
QString("./src"));
cliParser.addOption(srcbaseOption);
QCommandLineOption srcdirOption(Asciidoc::OPTION_SRCDIR,
QObject::tr("Source dir for source macro"),
Asciidoc::OPTION_SRCDIR,
QString("."));
cliParser.addOption(srcdirOption);
QCommandLineOption srclangOption(Asciidoc::OPTION_SRCLANG,
QObject::tr("Default language for source macro"),
Asciidoc::OPTION_SRCLANG,
QString("java"));
cliParser.addOption(srclangOption);
QCommandLineOption srcextOption(Asciidoc::OPTION_SRCEXT,
QObject::tr("Default file extension for source macro"),
Asciidoc::OPTION_SRCEXT,
QString(".java"));
cliParser.addOption(srcextOption);
QCommandLineOption srcnumberedOption(Asciidoc::OPTION_SRCNUMBERED,
QObject::tr("Set wether or not source code shall be displayed with line numbers"),
Asciidoc::OPTION_SRCNUMBERED,
QString(""));
cliParser.addOption(srcnumberedOption);
QCommandLineOption asciidocOption(Asciidoc::OPTION_ASCIIDOC_EXECUTABLE,
QObject::tr("Path to ASCIIDOC executable"),
Asciidoc::OPTION_ASCIIDOC_EXECUTABLE,
Asciidoc::OPTION_ASCIIDOC_EXECUTABLE_DEFAULT);
cliParser.addOption(asciidocOption);
QCommandLineOption blockdiagOption(Asciidoc::OPTION_BLOCKDIAG_EXECUTABLE,
QObject::tr("Path to blockdiag executable"),
Asciidoc::OPTION_BLOCKDIAG_EXECUTABLE,
Asciidoc::OPTION_BLOCKDIAG_EXECUTABLE_DEFAULT);
cliParser.addOption(blockdiagOption);
QCommandLineOption javaOption(Asciidoc::OPTION_JAVA_EXECUTABLE,
QObject::tr("Path to Java executable"),
Asciidoc::OPTION_JAVA_EXECUTABLE,
Asciidoc::OPTION_JAVA_EXECUTABLE_DEFAULT);
cliParser.addOption(javaOption);
QCommandLineOption plantumlOption(Asciidoc::OPTION_PLANTUML_JAR,
QObject::tr("Path to plantuml executable JAR archive"),
Asciidoc::OPTION_PLANTUML_JAR,
Asciidoc::OPTION_PLANTUML_JAR_DEFAULT);
cliParser.addOption(plantumlOption);
QCommandLineOption macro_configdirOption(Asciidoc::OPTION_MACRO_CONFIGDIR,
QObject::tr("Directory containing macro configuration files"),
Asciidoc::OPTION_MACRO_CONFIGDIR,
QString("."));
cliParser.addOption(macro_configdirOption);
QCommandLineOption hintcountOption(Asciidoc::OPTION_HINTCOUNT,
QObject::tr("Hint count for inline macro and anchor rule"),
Asciidoc::OPTION_HINTCOUNT,
QString("200"));
cliParser.addOption(hintcountOption);
QCommandLineOption adocattributeOption(Asciidoc::ADOCOPT_ATTRIBUTE,
QObject::tr("Asciidoc attributes"),
Asciidoc::ADOCOPT_ATTRIBUTE);
cliParser.addOption(adocattributeOption);
QCommandLineOption adocbackendOption(Asciidoc::ADOCOPT_BACKEND,
QObject::tr("Asciidoc backend option"),
Asciidoc::ADOCOPT_BACKEND);
cliParser.addOption(adocbackendOption);
QCommandLineOption adocoutputOption(Asciidoc::ADOCOPT_OUTPUT,
QObject::tr("Asciidoc output options"),
Asciidoc::ADOCOPT_OUTPUT);
cliParser.addOption(adocoutputOption);
// Process parameters
cliParser.process(a);
if (cliParser.isSet(traceOption)) {
qxtLog->setMinimumLevel(QxtLogger::TraceLevel);
}
QCoreApplication::setOrganizationName(notr(ORGANIZATION_NAME));
QCoreApplication::setOrganizationDomain(notr(ORGANIZATION_DOMAIN));
QCoreApplication::setApplicationName(notr(APPLICATION_NAME));
QCoreApplication::setApplicationVersion(notr(APPLICATION_VERSION));
Application application;
QStringList positionals = cliParser.positionalArguments();
if (positionals.size() == 0) {
cliParser.showHelp(-1);
}
QString filename = positionals.at(0);
application.setFileName(filename);
application.addContextVariable(Asciidoc::OPTION_DOCBASE, cliParser.value(Asciidoc::OPTION_DOCBASE));
application.addContextVariable(Asciidoc::OPTION_DOCSUFFIX, cliParser.value(Asciidoc::OPTION_DOCSUFFIX));
application.addContextVariable(Asciidoc::OPTION_JAVAPKG, cliParser.value(Asciidoc::OPTION_JAVAPKG));
application.addContextVariable(Asciidoc::OPTION_SRCBASE, cliParser.value(Asciidoc::OPTION_SRCBASE));
application.addContextVariable(Asciidoc::OPTION_SRCDIR, cliParser.value(Asciidoc::OPTION_SRCDIR));
application.addContextVariable(Asciidoc::OPTION_SRCLANG, cliParser.value(Asciidoc::OPTION_SRCLANG));
application.addContextVariable(Asciidoc::OPTION_SRCEXT, cliParser.value(Asciidoc::OPTION_SRCEXT));
application.addContextVariable(Asciidoc::OPTION_SRCNUMBERED, cliParser.value(Asciidoc::OPTION_SRCNUMBERED));
application.addContextVariable(Asciidoc::OPTION_ASCIIDOC_EXECUTABLE, cliParser.value(Asciidoc::OPTION_ASCIIDOC_EXECUTABLE));
application.addContextVariable(Asciidoc::OPTION_MACRO_CONFIGDIR, cliParser.value(Asciidoc::OPTION_MACRO_CONFIGDIR));
application.addContextVariable(Asciidoc::ADOCOPT_BACKEND, cliParser.value(Asciidoc::ADOCOPT_BACKEND));
application.addContextVariable(Asciidoc::ADOCOPT_OUTPUT, cliParser.value(Asciidoc::ADOCOPT_OUTPUT));
if (!cliParser.value(Asciidoc::ADOCOPT_OUTPUT).isEmpty()) {
application.setOutputFilename(cliParser.value(Asciidoc::ADOCOPT_OUTPUT));
}
if (cliParser.isSet(debugOption)) {
application.setDebug();
}
if (cliParser.isSet(dependencyOption)) {
application.setGenerateDependencyOnly(true);
qxtLog->removeLoggerEngine("stdout");
}
if (cliParser.isSet(preprocessOnlyOption)) {
application.setPreprocessOnly(true);
}
if (cliParser.isSet(urlcheckOption)) {
application.setUrlCheck(false);
}
QTimer::singleShot(0, &application, SLOT(run()));
return a.exec();
}