From 792815e9eaae89138c09846fc7f86f57cf0603a0 Mon Sep 17 00:00:00 2001 From: LaGrunge Date: Mon, 30 Sep 2019 10:51:42 +0000 Subject: [PATCH] Generator version console flag --- generator/data_version.cpp | 11 +++++++++++ generator/data_version.hpp | 2 +- generator/generator_tool/generator_tool.cpp | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/generator/data_version.cpp b/generator/data_version.cpp index 579c312..bdebefe 100644 --- a/generator/data_version.cpp +++ b/generator/data_version.cpp @@ -50,6 +50,17 @@ void DataVersion::DumpToPath(std::string const & path) const LOG(LINFO, ("Version of data has been written in", filePath)); } +// static +std::string DataVersion::GetCodeVersion() +{ + base::JSONPtr json{json_object()}; + ToJSONObject(*json, "build_time", geocore::build_version::git::kTimestamp); + ToJSONObject(*json, "git_hash", geocore::build_version::git::kHash); + ToJSONObject(*json, "git_tag", geocore::build_version::git::kTag); + return base::DumpToString(json); +} + + // static DataVersion DataVersion::LoadFromPath(std::string const & path) { diff --git a/generator/data_version.hpp b/generator/data_version.hpp index 9413408..01d70b4 100644 --- a/generator/data_version.hpp +++ b/generator/data_version.hpp @@ -18,7 +18,7 @@ public: std::string GetVersionJson() const; void DumpToPath(std::string const & path) const; static DataVersion LoadFromPath(std::string const & path); - + static std::string GetCodeVersion(); private: DataVersion() = default; static std::string ReadWholeFile(std::string const & filePath); diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index 950470b..f3a7ebe 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -182,6 +182,7 @@ CliCommandOptions DefineOptions(int argc, char * argv[]) ("verbose", po::value(&o.m_verbose)->default_value(false), "Provide more detailed output.") + ("version", "get version") ("help", "produce help message"); po::variables_map vm; @@ -195,6 +196,12 @@ CliCommandOptions DefineOptions(int argc, char * argv[]) exit(1); } + if (vm.count("version")) + { + std::cout << generator::DataVersion::GetCodeVersion() << std::endl; + exit(1); + } + return o; }