$darkmode
main_version.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
25 #pragma once
26 
27 #include <iostream> // for ostream, cout
28 
29 #include <cloe/plugin.hpp> // for CLOE_PLUGIN_MANIFEST_VERSION
30 #include <cloe/utility/inja.hpp> // for inja_env
31 
32 #include "stack.hpp" // for CLOE_STACK_VERSION
33 
34 namespace engine {
35 
37  std::ostream& output = std::cout;
38 
39  // Flags:
40  bool output_json = false;
41  int json_indent = 2;
42 };
43 
44 inline int version(const VersionOptions& opt) {
45  cloe::Json v{
46  {"engine", CLOE_ENGINE_VERSION}, // from CMakeLists.txt
47  {"build_date", CLOE_ENGINE_TIMESTAMP}, // from CMakeLists.txt
48  {"stack", CLOE_STACK_VERSION}, // from "stack.hpp"
49  {"plugin_manifest", CLOE_PLUGIN_MANIFEST_VERSION}, // from <cloe/plugin.hpp>
50  {"feature_server", CLOE_ENGINE_WITH_SERVER ? true : false}, // from CMakeLists.txt
51  };
52 
53  if (opt.output_json) {
54  opt.output << v.dump(opt.json_indent) << std::endl;
55  } else {
56  auto env = cloe::utility::inja_env();
57  opt.output << env.render(R"(Cloe [[engine]]
58 
59 Engine Version: [[engine]]
60 Build Date: [[build_date]]
61 Stack: [[stack]]
62 Plugin Manifest: [[plugin_manifest]]
63 Features:
64  server: [[feature_server]]
65 )",
66  v);
67  }
68 
69  return EXIT_SUCCESS;
70 }
71 
72 } // namespace engine
inja::Environment inja_env()
Definition: inja.hpp:38
Definition: main_version.hpp:36