forked from andrew-hardin/cmake-git-version-tracking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_SJsonFormatter.cpp.in
More file actions
51 lines (39 loc) · 1.39 KB
/
runtime_SJsonFormatter.cpp.in
File metadata and controls
51 lines (39 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@GTML_INFO@
#include "@GTML_RUNTIME_JSON_FORMATTER_HEADER_PATH@"
#include "nlohmann/json.hpp"
#include <string>
namespace @GTML_RUNTIME_NAMESPACE@ {
namespace
{
nlohmann::ordered_json buildJson(const IGitInfo& info)
{
nlohmann::ordered_json json = {
{"isPopulated", info.isPopulated()},
{"commitAuthorName", std::string(info.commitAuthorName())},
{"commitAuthorEmail", std::string(info.commitAuthorEmail())},
{"commitHash", std::string(info.commitHash())},
{"commitShortHash", std::string(info.commitShortHash())},
{"commitDate", std::string(info.commitDate())},
{"commitSubject", std::string(info.commitSubject())},
{"commitBody", std::string(info.commitBody())},
{"describe", std::string(info.describe())},
{"branchName", std::string(info.branchName())},
{"latestTag", std::string(info.latestTag())},
{"latestTagName", std::string(info.latestTagName())}
};
if (const auto dirty = info.hasUncommittedChanges(); dirty.has_value())
json["hasUncommittedChanges"] = dirty.value();
else
json["hasUncommittedChanges"] = nullptr;
return json;
}
}
std::string SJsonFormatter::toString(const IGitInfo& info)
{
return buildJson(info).dump();
}
std::string SJsonFormatter::toPrettyString(const IGitInfo& info)
{
return buildJson(info).dump(2);
}
} // namespace @GTML_RUNTIME_NAMESPACE@