-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathmain.cc
93 lines (73 loc) · 2.18 KB
/
main.cc
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <filesystem>
#include <fstream>
#include <iostream>
#include <cxxopts.hpp>
#include <fmt/format.h>
#include <nlohmann/json.hpp>
#include <spdlog/spdlog.h>
#include "config.hpp"
#include "foo.h"
using json = nlohmann::json;
namespace fs = std::filesystem;
int main(int argc, char **argv)
{
std::cout << "JSON: " << NLOHMANN_JSON_VERSION_MAJOR << "."
<< NLOHMANN_JSON_VERSION_MINOR << "."
<< NLOHMANN_JSON_VERSION_PATCH << '\n';
std::cout << "FMT: " << FMT_VERSION << '\n';
std::cout << "CXXOPTS: " << CXXOPTS__VERSION_MAJOR << "."
<< CXXOPTS__VERSION_MINOR << "." << CXXOPTS__VERSION_PATCH
<< '\n';
std::cout << "SPDLOG: " << SPDLOG_VER_MAJOR << "." << SPDLOG_VER_MINOR
<< "." << SPDLOG_VER_PATCH << '\n';
std::cout << "\n\nUsage Example:\n";
// Compiler Warning and clang tidy error
// std::int32_t i = 0;
// Adress Sanitizer should see this
// char x[10];
// x[11] = 1;
const auto welcome_message =
fmt::format("Welcome to {} v{}\n", project_name, project_version);
spdlog::info(welcome_message);
cxxopts::Options options(project_name.data(), welcome_message);
options.add_options("arguments")("h,help", "Print usage")(
"f,filename",
"File name",
cxxopts::value<std::string>())(
"v,verbose",
"Verbose output",
cxxopts::value<bool>()->default_value("false"));
auto result = options.parse(argc, argv);
if (argc == 1 || result.count("help"))
{
std::cout << options.help() << '\n';
return 0;
}
auto filename = std::string{};
auto verbose = false;
if (result.count("filename"))
{
filename = result["filename"].as<std::string>();
}
else
{
return 1;
}
verbose = result["verbose"].as<bool>();
if (verbose)
{
fmt::print("Opening file: {}\n", filename);
}
auto ifs = std::ifstream{filename};
if (!ifs.is_open())
{
return 1;
}
const auto parsed_data = json::parse(ifs);
if (verbose)
{
const auto name = parsed_data["name"];
fmt::print("Name: {}\n", name);
}
return 0;
}