Use own command line parser.
This commit is contained in:
parent
792ff33482
commit
8fff5026df
119
main.cpp
119
main.cpp
@ -10,6 +10,7 @@
|
||||
|
||||
#include "message_handler.h"
|
||||
#include "plugins/interfaces.h"
|
||||
#include "commandline_parser.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <memory>
|
||||
@ -21,6 +22,7 @@
|
||||
#include <QCommandLineParser>
|
||||
#include <QStandardPaths>
|
||||
#include <QMainWindow>
|
||||
#include <QSettings>
|
||||
|
||||
#include "update.h"
|
||||
#include "git/git_client.h"
|
||||
@ -51,7 +53,7 @@ int main(int argc, char *argv[]) {
|
||||
if (value != "C") {
|
||||
qputenv("LC_ALL", "C");
|
||||
}
|
||||
// qputenv("XDG_RUNTIME_DIR", "/run/user/0");
|
||||
// qputenv("XDG_RUNTIME_DIR", "/var/run/user/0");
|
||||
|
||||
openlog("ATB-UPDATE", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
|
||||
|
||||
@ -64,64 +66,44 @@ int main(int argc, char *argv[]) {
|
||||
setDebugLevel(LOG_NOTICE);
|
||||
}
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("Download tool for downloading device controller firmware, printer json-files and executing opkg-commands.");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
|
||||
QCommandLineOption pluginDirectoryOption(QStringList() << "plugin-directory" << "plugin-directory",
|
||||
QCoreApplication::translate("main", "Where to find dc-plugin."),
|
||||
QCoreApplication::translate("main", "directory"));
|
||||
QString const pluginDefault = "/usr/lib";
|
||||
pluginDirectoryOption.setDefaultValue(pluginDefault);
|
||||
parser.addOption(pluginDirectoryOption);
|
||||
|
||||
QCommandLineOption pluginNameOption(QStringList() << "plugin-name" << "plugin-name",
|
||||
QCoreApplication::translate("main", "Name of dc-plugin."),
|
||||
QCoreApplication::translate("main", "directory"));
|
||||
QString const pluginNameDefault = "libCAslave.so";
|
||||
pluginNameOption.setDefaultValue(pluginNameDefault);
|
||||
parser.addOption(pluginNameOption);
|
||||
|
||||
QCommandLineOption noDownloadOption("no-psa-hardware-update",
|
||||
QCoreApplication::translate("main", "Do not update the PSA firmware (json, device-controller)."));
|
||||
parser.addOption(noDownloadOption);
|
||||
|
||||
QCommandLineOption workingDirectoryOption(QStringList() << "working-directory" << "working-directory",
|
||||
QCoreApplication::translate("main", "working directory of update-script."),
|
||||
QCoreApplication::translate("main", "directory"));
|
||||
QString const workingDirectoryDefault = "/opt/app/tools/atbupdate";
|
||||
workingDirectoryOption.setDefaultValue(workingDirectoryDefault);
|
||||
parser.addOption(workingDirectoryOption);
|
||||
|
||||
QCommandLineOption dryRunOption(QStringList() << "d" << "dry-run",
|
||||
QCoreApplication::translate("main", "Start ATBUpdateTool in dry-run-mode. No actual actions."));
|
||||
parser.addOption(dryRunOption);
|
||||
|
||||
QCommandLineOption extendedVersionOption(QStringList() << "V" << "extended-version",
|
||||
QCoreApplication::translate("main", "Show extended version (including last git commit)."));
|
||||
parser.addOption(extendedVersionOption);
|
||||
|
||||
QCommandLineOption yoctoVersionOption(QStringList() << "y" << "yocto-version",
|
||||
QCoreApplication::translate("main", "Show yocto version of ATBUpdateTool."));
|
||||
parser.addOption(yoctoVersionOption);
|
||||
|
||||
QCommandLineOption yoctoInstallStatusOption(QStringList() << "Y" << "yocto-install",
|
||||
QCoreApplication::translate("main", "Show yocto install status of ATBUpdateTool."));
|
||||
parser.addOption(yoctoInstallStatusOption);
|
||||
|
||||
// Process the actual command line arguments given by the user
|
||||
CommandLineParser parser;
|
||||
parser.process(a);
|
||||
QString plugInDir = parser.value(pluginDirectoryOption);
|
||||
QString plugInName = parser.value(pluginNameOption);
|
||||
QString workingDir = parser.value(workingDirectoryOption);
|
||||
bool const dryRun = parser.isSet(dryRunOption);
|
||||
bool const noUpdatePsaHardware = parser.isSet(noDownloadOption);
|
||||
bool const showYoctoVersion = parser.isSet(yoctoVersionOption);
|
||||
bool const showYoctoInstallStatus = parser.isSet(yoctoInstallStatusOption);
|
||||
bool const showExtendedVersion = parser.isSet(extendedVersionOption);
|
||||
parser.readSettings();
|
||||
|
||||
QString repositoryUrl = parser.repositoryUrl();
|
||||
QString plugInDir = parser.plugInDir();
|
||||
QString plugInName = parser.plugInName();
|
||||
QString workingDir = parser.workingDir();
|
||||
bool const dryRun = parser.dryRun();
|
||||
bool const noUpdatePsaHardware = parser.noUpdatePsaHardware();
|
||||
bool const showYoctoVersion = parser.yoctoVersion();
|
||||
bool const showYoctoInstallStatus = parser.yoctoInstallStatus();
|
||||
bool const showExtendedVersion = parser.extendedVersion();
|
||||
|
||||
QString const rtPath = QCoreApplication::applicationDirPath();
|
||||
|
||||
qInfo() << "pwd ......................" << rtPath;
|
||||
qInfo() << "repositoryUrl ............" << repositoryUrl;
|
||||
qInfo() << "plugInDir ................" << plugInDir;
|
||||
qInfo() << "plugInName ..............." << plugInName;
|
||||
qInfo() << "workingDir ..............." << workingDir;
|
||||
qInfo() << "dryRun ..................." << dryRun;
|
||||
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
|
||||
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
|
||||
|
||||
if (showExtendedVersion) {
|
||||
printf(APP_EXTENDED_VERSION"\n");
|
||||
return 0;
|
||||
}
|
||||
if (showYoctoVersion) {
|
||||
printf("%s\n", Worker::getATBUpdateToolYoctoVersion().toStdString().c_str());
|
||||
return 0;
|
||||
}
|
||||
if (showYoctoInstallStatus) {
|
||||
printf("%s\n", Worker::getATBUpdateToolYoctoInstallationStatus().toStdString().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int machineNr = Utils::read1stLineOfFile("/etc/machine_nr");
|
||||
int customerNr = Utils::read1stLineOfFile("/etc/cust_nr");
|
||||
int zoneNr = Utils::read1stLineOfFile("/etc/zone_nr");
|
||||
@ -131,20 +113,6 @@ int main(int argc, char *argv[]) {
|
||||
QThread::currentThread()->setObjectName("main thread");
|
||||
qInfo() << "Main thread" << QThread::currentThreadId();
|
||||
|
||||
if (showExtendedVersion) {
|
||||
printf(APP_EXTENDED_VERSION"\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (showYoctoVersion) {
|
||||
printf("%s\n", Worker::getATBUpdateToolYoctoVersion().toStdString().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (showYoctoInstallStatus) {
|
||||
printf("%s\n", Worker::getATBUpdateToolYoctoInstallationStatus().toStdString().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!QDir(plugInDir).exists()) {
|
||||
qCritical() << plugInDir
|
||||
@ -152,16 +120,6 @@ int main(int argc, char *argv[]) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
qInfo() << "pwd ......................" << rtPath;
|
||||
qInfo() << "plugInDir ................" << plugInDir;
|
||||
qInfo() << "plugInName ..............." << plugInName;
|
||||
qInfo() << "workingDir ..............." << workingDir;
|
||||
qInfo() << "dryRun ..................." << dryRun;
|
||||
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
|
||||
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
|
||||
//qInfo() << "yocto-version ............" << Worker::getATBUpdateToolYoctoVersion();
|
||||
//qInfo() << "yocto-install-status ....." << Worker::getATBUpdateToolYoctoInstallationStatus();
|
||||
|
||||
// before loading the library, delete all possible shared memory segments
|
||||
#if defined Q_OS_LINUX || defined Q_OS_UNIX
|
||||
// system("rm -rf /tmp/qipc*");
|
||||
@ -172,6 +130,7 @@ int main(int argc, char *argv[]) {
|
||||
Worker worker(customerNr,
|
||||
machineNr,
|
||||
zoneNr,
|
||||
repositoryUrl,
|
||||
branchName,
|
||||
plugInDir,
|
||||
plugInName,
|
||||
|
Loading…
Reference in New Issue
Block a user