osb/source/base/StarVersionOptionParser.cpp

47 lines
1.2 KiB
C++
Raw Normal View History

2023-06-20 04:33:09 +00:00
#include "StarVersionOptionParser.hpp"
#include "StarFile.hpp"
namespace Star {
void VersionOptionParser::printVersion(std::ostream& os) {
2023-06-27 10:23:44 +00:00
format(os, "Starbound Version {} ({})\n", StarVersionString, StarArchitectureString);
format(os, "Source Identifier - {}\n", StarSourceIdentifierString);
2023-06-20 04:33:09 +00:00
}
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)
2023-06-27 10:23:44 +00:00
coutf("Error: {}\n", err);
2023-06-20 04:33:09 +00:00
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));
}
}