Use custom command line parser.
Checkout branch after cloning.
This commit is contained in:
61
Git/main.cpp
61
Git/main.cpp
@@ -8,6 +8,7 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
#include "message_handler.h"
|
#include "message_handler.h"
|
||||||
#include "utils_internal.h"
|
#include "utils_internal.h"
|
||||||
#include "git_command.h"
|
#include "git_command.h"
|
||||||
|
#include "commandline_parser.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
QByteArray const value = qgetenv("LC_ALL");
|
QByteArray const value = qgetenv("LC_ALL");
|
||||||
@@ -41,7 +43,7 @@ int main(int argc, char **argv) {
|
|||||||
setDebugLevel(LOG_NOTICE);
|
setDebugLevel(LOG_NOTICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
QCommandLineParser parser;
|
CommandLineParser parser;
|
||||||
parser.setApplicationDescription("git-commands for the update-system");
|
parser.setApplicationDescription("git-commands for the update-system");
|
||||||
|
|
||||||
QCommandLineOption const checkCustomerRepositoryOption{"check"};
|
QCommandLineOption const checkCustomerRepositoryOption{"check"};
|
||||||
@@ -56,6 +58,54 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
QCommandLineOption verboseOption{parser.addVersionOption()};
|
QCommandLineOption verboseOption{parser.addVersionOption()};
|
||||||
parser.process(a);
|
parser.process(a);
|
||||||
|
parser.readSettings();
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// note: also used in initEnv().
|
||||||
|
|
||||||
|
QString repositoryUrl = parser.repositoryUrl();
|
||||||
|
|
||||||
|
if (repositoryUrl.endsWith('/')) {
|
||||||
|
repositoryUrl.chop(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!repositoryUrl.isEmpty()) {
|
||||||
|
qInfo() << "customer repository url" << repositoryUrl;
|
||||||
|
} else {
|
||||||
|
qCritical() << "ERROR customer repository url empty. git commands might fail.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repositoryUrl.contains("ptu-config.atb-comm.de")) {
|
||||||
|
QString gitSSHCommand("");
|
||||||
|
QByteArray const v = qgetenv("GIT_SSH_COMMAND");
|
||||||
|
if (v.isEmpty()) {
|
||||||
|
QString sshKeyFile("/opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig");
|
||||||
|
if (QFileInfo(sshKeyFile).exists()) {
|
||||||
|
if (qgetenv("GIT_SSH_COMMAND").isNull()) {
|
||||||
|
gitSSHCommand = "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig";
|
||||||
|
if (!qputenv("GIT_SSH_COMMAND", QByteArray(gitSSHCommand.toStdString().c_str()))) {
|
||||||
|
qCritical() << "ERROR: GIT_SSH_COMMAND not put into env. Exiting...";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << "ERROR ssh-key-file" << sshKeyFile << "does not exists. Exiting...";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gitSSHCommand = QString(v.toStdString().c_str());
|
||||||
|
qInfo() << "GIT_SSH_COMMAND already set in enviroment:" << gitSSHCommand;
|
||||||
|
if (gitSSHCommand != "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig") {
|
||||||
|
qCritical() << "ERROR" << gitSSHCommand << "wrong. Exiting...";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gitSSHCommand.isEmpty()) {
|
||||||
|
qInfo() << "GIT_SSH_COMMAND .........." << gitSSHCommand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (parser.isSet(verboseOption)) {
|
if (parser.isSet(verboseOption)) {
|
||||||
parser.showVersion();
|
parser.showVersion();
|
||||||
@@ -108,12 +158,13 @@ int main(int argc, char **argv) {
|
|||||||
if (!gitCmd.clone()) {
|
if (!gitCmd.clone()) {
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
if (!gitCmd.checkout()) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
qCritical() << internal::GIT_CUSTOMER_REPO_CLONED;
|
||||||
|
return internal::GIT_CLONED_CODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//int const machineNr = read1stLineOfFile("/mnt/system_data/machine_nr");
|
|
||||||
//int const customerNr = read1stLineOfFile("/mnt/system_data/cust_nr");
|
|
||||||
//int const zoneNr = read1stLineOfFile("/mnt/system_data/zone_nr");
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user