-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathglobal_options.h
97 lines (89 loc) · 2.43 KB
/
global_options.h
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
94
95
96
97
// global_options.h
// Copyright 2017 The NeoPG developers
//
// NeoPG is released under the Simplified BSD License (see license.txt)
#pragma once
#include <iostream>
#include <spdlog/spdlog.h>
#include <CLI11.hpp>
#include <rang.hpp>
namespace rang {
std::istream& operator>>(std::istream& in, rang::control& when) {
std::string label;
in >> label;
if (label == "always")
when = rang::control::Force;
else if (label == "never")
when = rang::control::Off;
else if (label == "auto")
when = rang::control::Auto;
else {
// We are not pushing back what we couldn't parse. Seems to be OK.
in.setstate(std::ios_base::failbit);
}
return in;
}
std::ostream& operator<<(std::ostream& out, const rang::control& when) {
switch (when) {
case rang::control::Force:
return out << "always";
case rang::control::Off:
return out << "never";
default:
return out << "auto";
}
}
} // namespace rang
namespace spdlog {
namespace level {
std::istream& operator>>(std::istream& in, spdlog::level::level_enum& level) {
std::string label;
in >> label;
if (label == "trace")
level = spdlog::level::trace;
else if (label == "debug")
level = spdlog::level::debug;
else if (label == "info")
level = spdlog::level::info;
else if (label == "warning")
level = spdlog::level::warn;
else if (label == "error")
level = spdlog::level::err;
else if (label == "critical")
level = spdlog::level::critical;
else if (label == "off")
level = spdlog::level::off;
else {
// We are not pushing back what we couldn't parse. Seems to be OK.
in.setstate(std::ios_base::failbit);
}
return in;
}
std::ostream& operator<<(std::ostream& out,
const spdlog::level::level_enum& level) {
switch (level) {
case spdlog::level::trace:
return out << "trace";
case spdlog::level::debug:
return out << "debug";
case spdlog::level::info:
return out << "info";
case spdlog::level::warn:
return out << "warning";
case spdlog::level::err:
return out << "error";
case spdlog::level::critical:
return out << "critical";
case spdlog::level::off:
return out << "off";
default:
throw std::logic_error("unknown logging level");
}
}
} // namespace level
} // namespace spdlog
class GlobalOptions {
public:
rang::control color{rang::control::Auto};
spdlog::level::level_enum log_level{spdlog::level::warn};
};