1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +00:00

LibCore: Make --version print same version as in LibGUI's About dialogs

Making every binary's behavior depend on the current git hash seems a
bit questionable to me, but we should be self-consistent about this.
This commit is contained in:
Nico Weber 2021-08-14 18:50:52 -04:00 committed by Andreas Kling
parent faa2c74b49
commit f25be94487
2 changed files with 17 additions and 1 deletions

View file

@ -7,6 +7,7 @@
#include <AK/Format.h>
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/ConfigFile.h>
#include <getopt.h>
#include <limits.h>
#include <math.h>
@ -155,7 +156,7 @@ bool ArgsParser::parse(int argc, char* const* argv, FailureBehavior failure_beha
// We're done parsing! :)
// Now let's show version or help if requested.
if (m_show_version) {
outln(stdout, "git");
print_version(stdout);
if (failure_behavior == FailureBehavior::Exit || failure_behavior == FailureBehavior::PrintUsageAndExit)
exit(0);
return false;
@ -241,6 +242,20 @@ void ArgsParser::print_usage(FILE* file, const char* argv0)
}
}
void ArgsParser::print_version(FILE* file)
{
auto version_config = Core::ConfigFile::open("/res/version.ini");
auto major_version = version_config->read_entry("Version", "Major", "0");
auto minor_version = version_config->read_entry("Version", "Minor", "0");
StringBuilder builder;
builder.appendff("{}.{}", major_version, minor_version);
if (auto git_version = version_config->read_entry("Version", "Git", ""); git_version != "")
builder.appendff(".g{}", git_version);
outln(file, builder.to_string());
}
void ArgsParser::add_option(Option&& option)
{
m_options.append(move(option));