v1.4.4
This commit is contained in:
commit
9c94d113d3
10260 changed files with 1237388 additions and 0 deletions
46
source/base/StarVersionOptionParser.cpp
Normal file
46
source/base/StarVersionOptionParser.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include "StarVersionOptionParser.hpp"
|
||||
#include "StarFile.hpp"
|
||||
|
||||
namespace Star {
|
||||
|
||||
void VersionOptionParser::printVersion(std::ostream& os) {
|
||||
format(os, "Starbound Version %s (%s)\n", StarVersionString, StarArchitectureString);
|
||||
format(os, "Source Identifier - %s\n", StarSourceIdentifierString);
|
||||
}
|
||||
|
||||
VersionOptionParser::VersionOptionParser() {
|
||||
addSwitch("help", "Show help text");
|
||||
addSwitch("version", "Print version info");
|
||||
}
|
||||
|
||||
VersionOptionParser::Options VersionOptionParser::parseOrDie(StringList const& cmdLineArguments) const {
|
||||
Options options;
|
||||
StringList errors;
|
||||
tie(options, errors) = OptionParser::parseOptions(cmdLineArguments);
|
||||
|
||||
if (options.switches.contains("version"))
|
||||
printVersion(std::cout);
|
||||
|
||||
if (options.switches.contains("help"))
|
||||
printHelp(std::cout);
|
||||
|
||||
if (options.switches.contains("version") || options.switches.contains("help"))
|
||||
std::exit(0);
|
||||
|
||||
if (!errors.empty()) {
|
||||
for (auto const& err : errors)
|
||||
coutf("Error: %s\n", err);
|
||||
coutf("\n");
|
||||
printHelp(std::cout);
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
VersionOptionParser::Options VersionOptionParser::commandParseOrDie(int argc, char** argv) {
|
||||
setCommandName(File::baseName(argv[0]));
|
||||
return parseOrDie(StringList(argc - 1, argv + 1));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue