added class containing program arguments

This commit is contained in:
fourtf 2019-09-22 15:30:04 +02:00
parent 456065f508
commit 7e555843ca
5 changed files with 51 additions and 0 deletions

View file

@ -76,6 +76,7 @@ SOURCES += \
src/Application.cpp \ src/Application.cpp \
src/autogenerated/ResourcesAutogen.cpp \ src/autogenerated/ResourcesAutogen.cpp \
src/BrowserExtension.cpp \ src/BrowserExtension.cpp \
src/common/Args.cpp \
src/common/Channel.cpp \ src/common/Channel.cpp \
src/common/ChannelChatters.cpp \ src/common/ChannelChatters.cpp \
src/common/CompletionModel.cpp \ src/common/CompletionModel.cpp \
@ -233,6 +234,7 @@ HEADERS += \
src/autogenerated/ResourcesAutogen.hpp \ src/autogenerated/ResourcesAutogen.hpp \
src/BrowserExtension.hpp \ src/BrowserExtension.hpp \
src/common/Aliases.hpp \ src/common/Aliases.hpp \
src/common/Args.hpp \
src/common/Atomic.hpp \ src/common/Atomic.hpp \
src/common/Channel.hpp \ src/common/Channel.hpp \
src/common/ChannelChatters.hpp \ src/common/ChannelChatters.hpp \

View file

@ -2,6 +2,7 @@
#include <atomic> #include <atomic>
#include "common/Args.hpp"
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandController.hpp" #include "controllers/commands/CommandController.hpp"
#include "controllers/highlights/HighlightController.hpp" #include "controllers/highlights/HighlightController.hpp"

30
src/common/Args.cpp Normal file
View file

@ -0,0 +1,30 @@
#include "Args.hpp"
namespace chatterino {
Args::Args(const QStringList &args)
{
for (auto &&arg : args)
{
if (arg == "--crash-recovery")
{
this->crashRecovery = true;
}
}
}
static Args *instance = nullptr;
void initArgs(const QStringList &args)
{
instance = new Args(args);
}
const Args &getArgs()
{
assert(instance);
return *instance;
}
} // namespace chatterino

17
src/common/Args.hpp Normal file
View file

@ -0,0 +1,17 @@
#pragma once
namespace chatterino {
/// Command line arguments passed to Chatterino.
class Args
{
public:
Args(const QStringList &args);
bool crashRecovery{};
};
void initArgs(const QStringList &args);
const Args &getArgs();
} // namespace chatterino

View file

@ -26,6 +26,7 @@ int main(int argc, char **argv)
} }
else else
{ {
initArgs(args);
Paths paths; Paths paths;
Settings settings(paths.settingsDirectory); Settings settings(paths.settingsDirectory);