This commit is contained in:
mrbesen 2022-04-26 19:36:15 +02:00
parent ee5a0017ea
commit 4e515ae8a0
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
4 changed files with 57 additions and 4 deletions

7
include/arg.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
struct Args {
int debugLog = 0; // cast to bool later
};
Args parseArgs(int argc, char** argv);

View File

@ -23,6 +23,7 @@ defineReplace(prependAll) {
}
SOURCES += \
src/arg.cpp \
src/config.cpp \
src/datadragon.cpp \
src/datadragonimagecache.cpp \
@ -46,6 +47,7 @@ SOURCES += \
# mainwindow.cpp
HEADERS += \
include/arg.h \
include/config.h \
include/datadragon.h \
include/datadragonimagecache.h \

37
src/arg.cpp Normal file
View File

@ -0,0 +1,37 @@
#include "arg.h"
#include <getopt.h>
#include <stdlib.h>
Args parseArgs(int argc, char** argv) {
Args a;
while (1) {
static struct option long_options[] = {
{"debug-log", no_argument, &a.debugLog, 1},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
int c = getopt_long (argc, argv, "", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1) break;
switch (c) {
case 0:
/* If this option set a flag, do nothing else now. */
break;
case '?':
/* getopt_long already printed an error message. */
break;
default:
abort();
}
}
return a;
}

View File

@ -9,6 +9,7 @@
#include <Log.h>
#include "arg.h"
#include "mainwindow.h"
#include "lolautoaccept.h"
@ -29,19 +30,25 @@ static std::string getBaseString(char** argv) {
int main(int argc, char** argv) {
Log::init();
Log::setConsoleLogLevel(Log::Level::INFO);
// Log::addLogfile("log.txt", Log::Level::TRACE);
#if __unix__
Log::setColoredOutput(true);
#endif
Log::info << "Hello, World!";
Log::note << "Using Locale: " << QLocale().name().toStdString();
if(argc == 0) {
Log::fatal << "arg[0] is not set";
return 1;
}
Args args = parseArgs(argc, argv);
if(args.debugLog) {
Log::setConsoleLogLevel(Log::Level::TRACE);
Log::addLogfile("log.txt", Log::Level::TRACE);
Log::debug << "debug Log enabled";
}
Log::info << "Hello, World!";
Log::note << "Using Locale: " << QLocale().name().toStdString();
std::string base = getBaseString(argv);
Log::info << "appbase: " << base;
Matcher::setPathBase(base);