Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
terminalparser.cpp
1 //This program is free software: you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation, either version 3 of the License, or
4 //(at your option) any later version.
5 
6 //This program is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
10 
11 #include "terminalparser.hpp"
12 using namespace Huggle;
13 using namespace std;
14 
15 TerminalParser::TerminalParser(int argc_, QStringList argv)
16 {
17  this->argc = argc_;
18  this->Silent = false;
19  this->args = argv;
20 }
21 
22 bool TerminalParser::Parse()
23 {
24  int x = 1;
25  while (x < this->args.count())
26  {
27  bool valid = false;
28  QString text = this->args.at(x);
29  if (text == "-h" || text == "--help")
30  {
31  DisplayHelp();
32  return true;
33  }
34  if (!text.startsWith("--") && text.startsWith("-"))
35  {
36  text = text.mid(1);
37  while (text.length())
38  {
39  if (this->ParseChar(text.at(0)))
40  {
41  return true;
42  }
43  text = text.mid(1);
44  }
45  valid = true;
46  }
47  if (text == "--safe")
48  {
50  valid = true;
51  }
52  if (!valid)
53  {
54  if (!Silent)
55  {
56  cout << (QString("This parameter isn't valid: ") + text).toStdString() << endl;
57  }
58  return true;
59  }
60  x++;
61  }
62  return false;
63 }
64 
65 bool TerminalParser::ParseChar(QChar x)
66 {
67  switch (x.toAscii())
68  {
69  case 'v':
71  return false;
72  case 'h':
73  this->DisplayHelp();
74  return true;
75  }
76  return false;
77 }
78 
79 void TerminalParser::DisplayHelp()
80 {
81  if (Silent)
82  {
83  return;
84  }
85  cout << "Huggle 3 QT-LX" << endl << endl;
86  cout << "Parameters:" << endl;
87  cout << " -v: Increases verbosity" << endl;
88  cout << " --safe: Start huggle in special mode where lot of stuff is skipped during load" << endl;
89  cout << " -h | --help: Display this help" << endl<< endl;
90  cout << "Huggle is open source, contribute at https://github.com/huggle/huggle3-qt-lx" << endl;
91 }
static unsigned int Verbosity
Verbosity for debugging to terminal etc, can be switched with parameter –verbosity.
static bool _SafeMode
If this is true some functionalities will be disabled.