-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrez.cpp
118 lines (91 loc) · 2.34 KB
/
rez.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <cstdlib>
#include <filesystem>
#include <functional>
#include <iostream>
#include <map>
#include <string_view>
#include <unordered_set>
#include <vector>
using std::literals::string_view_literals::operator""sv;
static int cmake_init() {
return system("cmake -B build .");
}
static int build() {
const int status{ cmake_init() };
if (status) {
return status;
}
return system("cmake --build build --config Release");
}
static int install() {
const int status{ build() };
if (status) {
return status;
}
return system("cmake --build build --target install");
}
static int uninstall() {
const int status{ cmake_init() };
if (status) {
return status;
}
return system("cmake --build build --target uninstall");
}
static int run() {
const int status{ install() };
if (status) {
return status;
}
return system("athena");
}
static int clean_bin() {
std::filesystem::remove_all("bin");
return EXIT_SUCCESS;
}
static int clean_cmake() {
std::filesystem::remove_all("build");
return EXIT_SUCCESS;
}
static int clean() {
clean_bin();
clean_cmake();
return EXIT_SUCCESS;
}
int main(int argc, const char **argv) {
const std::vector<std::string_view> args{ argv + 1, argv + argc };
const std::function<int()> default_task{ run };
if (args.empty()) {
if (default_task()) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
const std::map<std::string_view, std::function<int()>> tasks{
{ "clean"sv, clean },
{ "clean_bin"sv, clean_bin },
{ "clean_cmake"sv, clean_cmake },
{ "cmake_init"sv, cmake_init },
{ "build"sv, build },
{ "install"sv, install },
{ "run"sv, run },
{ "uninstall"sv, uninstall }
};
if (args.front() == "-l") {
for (const auto &[name, _] : tasks) {
std::cout << name << "\n";
}
return EXIT_SUCCESS;
}
for (const std::string_view &arg : args) {
try {
const std::function<int()> f{ tasks.at(arg) };
if (f()) {
return EXIT_FAILURE;
}
} catch (std::out_of_range &e) {
std::cerr << "no such task: " << arg << "\n";
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}