aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 973ac58..ae40f60 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -31,8 +31,8 @@ int main(int argc, char **argv)
QCommandLineParser parser;
parser.setApplicationDescription("yet another no-frills browser");
- parser.addHelpOption();
- parser.addVersionOption();
+ QCommandLineOption helpOption = parser.addHelpOption();
+ QCommandLineOption versionOption = parser.addVersionOption();
// user config, ~/.config/smolbote/smolbote.cfg or empty if there is none
QCommandLineOption configOption({ "c", "config" }, "Set configuration file.", "path");
@@ -69,6 +69,14 @@ int main(int argc, char **argv)
// process calls exit() on unknown options
parser.parse(instance.arguments());
+ if(parser.isSet(helpOption)) {
+ parser.showHelp(0);
+ }
+
+ if(parser.isSet(versionOption)) {
+ parser.showVersion();
+ }
+
#ifdef QT_DEBUG
qDebug("config=%s", qUtf8Printable(parser.value(configOption)));
qDebug("default-config=%s", qUtf8Printable(parser.value(defaultConfigOption)));
@@ -100,7 +108,7 @@ int main(int argc, char **argv)
// we get their values
if(!parser.unknownOptionNames().isEmpty()) {
int _argc = parser.unknownOptionNames().length() + 1;
- const char* _argv[_argc];
+ const char *_argv[_argc];
// program_options requires 0 to be the program name, otherwise it seems to fail
_argv[0] = qUtf8Printable(instance.arguments().at(0));
@@ -108,7 +116,7 @@ int main(int argc, char **argv)
// create a list of unknown QCommandLineOption's
// parser.addOptions() takes a list, so this is a QList
QList<QCommandLineOption> opts;
- for (const QString &opt : parser.unknownOptionNames()) {
+ for(const QString &opt : parser.unknownOptionNames()) {
QCommandLineOption o(opt, "dummy desc", "dummy value");
opts.append(o);
}
@@ -118,7 +126,7 @@ int main(int argc, char **argv)
parser.parse(instance.arguments());
for(int i = 1; i < _argc; ++i) {
- _argv[i] = qUtf8Printable(QString("--%1=%2").arg(opts[i-1].names().at(0), parser.value(opts[i-1])));
+ _argv[i] = qUtf8Printable(QString("--%1=%2").arg(opts[i - 1].names().at(0), parser.value(opts[i - 1])));
}
qDebug("Parsing command-line overrides: %s", config->parse(_argc, _argv) ? "ok" : "failed");