Freeciv21
Develop your civilization from humble roots to a global empire
mpcmdline.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 // Qt
15 #include <QCommandLineParser>
16 
17 // utility
18 #include "fcintl.h"
19 // common
20 #include "version.h"
21 
22 // modinst
23 #include "modinst.h"
24 
25 #include "mpcmdline.h"
26 
27 extern struct fcmp_params fcmp;
28 
39 void fcmp_parse_cmdline(const QCoreApplication &app)
40 {
41  QCommandLineParser parser;
42  parser.addHelpOption();
43  parser.addVersionOption();
44 
45  bool ok = parser.addOptions(
46  {{{"d", _("debug")},
47  // TRANS: Do not translate "fatal", "critical", "warning", "info" or
48  // "debug". It's exactly what the user must type.
49  _("Set debug log level (fatal/critical/warning/info/debug)."),
50  _("LEVEL"),
51  QStringLiteral("info")},
52  {{"i", "install"},
53  _("Automatically install modpack from a given URL."),
54  // TRANS: Command line argument
55  _("URL")},
56  {{"L", "List"},
57  _("Load modpack list from given URL."),
58  // TRANS: Command line argument
59  _("URL")},
60  {{"p", "prefix"},
61  _("Install modpacks to given directory hierarchy."),
62  // TRANS: Command line argument
63  _("DIR")}});
64  if (!ok) {
65  qFatal("Adding command line arguments failed.");
66  exit(EXIT_FAILURE);
67  }
68 
69  // Parse
70  parser.process(app);
71 
72  // Process the parsed options
73  if (!log_init(parser.value(QStringLiteral("debug")))) {
74  exit(EXIT_FAILURE);
75  }
76  if (parser.isSet(QStringLiteral("List"))) {
77  fcmp.list_url =
78  QUrl::fromUserInput(parser.value(QStringLiteral("List")));
79  }
80  if (parser.isSet(QStringLiteral("prefix"))) {
81  fcmp.inst_prefix = parser.value(QStringLiteral("prefix"));
82  }
83  if (parser.isSet(QStringLiteral("install"))) {
84  fcmp.autoinstall = parser.value(QStringLiteral("install"));
85  }
86 
87  if (fcmp.inst_prefix.isNull()) {
89 
90  if (fcmp.inst_prefix.isNull()) {
91  qCritical("Cannot determine Freeciv21 storage directory.");
92  }
93  }
94 }
#define _(String)
Definition: fcintl.h:50
bool log_init(const QString &level_str, const QStringList &extra_rules)
Parses a log level string as provided by the user on the command line, and installs the corresponding...
Definition: log.cpp:55
struct fcmp_params fcmp
Definition: mpcli.cpp:35
void fcmp_parse_cmdline(const QCoreApplication &app)
Parse commandline parameters.
Definition: mpcmdline.cpp:39
QString freeciv_storage_dir()
Returns string which gives freeciv storage dir.
Definition: shared.cpp:419
QUrl list_url
Definition: modinst.h:20
QString autoinstall
Definition: modinst.h:22
QString inst_prefix
Definition: modinst.h:21