TrueReality  v0.1.1912
Utils.cpp
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 
22 #include <trVersion/Utils.h>
23 
24 #include <iostream>
25 #include <cstdlib>
26 #include <sstream>
27 
28 #include <osg/ArgumentParser>
29 #include <osgDB/FileNameUtils>
30 
31 #include <trUtil/Exception.h>
32 #include <trUtil/Logging/Log.h>
33 
34 /*
35  * Parses the command line variables that are passed in to the executable
36  */
37 void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel, bool &updateVer, bool &incVer, int &majVer, int &minVer, std::string &yymmVer, int &buildVer)
38 {
39  osg::ArgumentParser arguments(&argc, argv);
40 
41  arguments.getApplicationUsage()->setApplicationName(PROGRAM_NAME);
42 
43  arguments.getApplicationUsage()->addCommandLineOption("\n--setBuild ", "Sets the softwares Build version");
44  arguments.getApplicationUsage()->addCommandLineOption("\n--setYYMM ", "Sets the softwares YYMM version");
45  arguments.getApplicationUsage()->addCommandLineOption("\n--setMinor ", "Sets the softwares Minor version");
46  arguments.getApplicationUsage()->addCommandLineOption("\n--setMajor ", "Sets the softwares Major version");
47  arguments.getApplicationUsage()->addCommandLineOption("\n--setVer <Maj> <Min> <YYMM> <Build>", "Sets the softwares version");
48  arguments.getApplicationUsage()->addCommandLineOption("\n--incVer ", "Increments the softwares version");
49  arguments.getApplicationUsage()->addCommandLineOption("\n--updateVer ", "Update the softwares version using .hg Revision and current YYMM");
50  arguments.getApplicationUsage()->addCommandLineOption("\n--logFileName <filename> ", "The name of the log file to use. Defaults to TrueRealityLog.html");
51  arguments.getApplicationUsage()->addCommandLineOption("\n--logLevel <level> ", "Logging level to use. \nLevel options are: " + trUtil::Logging::LOG_DEBUG_STR + ", " +
55  arguments.getApplicationUsage()->addCommandLineOption("\n--help, /help, -h, /h, /? ", "Show this help screen.");
56 
57  if (arguments.read("--help") == true ||
58  arguments.read("/help") == true ||
59  arguments.read("-h") == true ||
60  arguments.read("/h") == true ||
61  arguments.read("/?") == true)
62  {
63  arguments.getApplicationUsage()->write(std::cout);
64  exit(0);
65  }
66 
67  if (arguments.read("--updateVer") == true)
68  {
69  updateVer = true;
70  }
71 
72  if (arguments.read("--incVer") == true)
73  {
74  incVer = true;
75  }
76 
77  arguments.read("--logFileName", logFileName);
78  arguments.read("--logLevel", logLevel);
79 
80  arguments.read("--setBuild", buildVer);
81  arguments.read("--setYYMM", yymmVer);
82  arguments.read("--setMinor", minVer);
83  arguments.read("--setMajor", majVer);
84  arguments.read("--setVer", majVer, minVer, yymmVer, buildVer);
85 }
static const std::string PROGRAM_NAME
Definition: Utils.h:25
static const std::string LOG_ERROR_STR("Error")
String value for ERROR Logging level.
static const std::string LOG_WARNING_STR("Warning")
String value for WARNING Logging level.
static const std::string LOG_DEBUG_STR("Debug")
String value for DEBUG Logging level.
void ParseCmdLineArgs(int &argc, char **argv, std::string &logFileName, std::string &logLevel, bool &updateVer, bool &incVer, int &majVer, int &minVer, std::string &yymmVer, int &buildVer)
Definition: Utils.cpp:37
static const std::string LOG_INFO_STR("Info")
String value for INFO Logging level.