-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain_clumpy.cc
60 lines (54 loc) · 1.56 KB
/
main_clumpy.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
#include "clumpy_command.hh"
#include "fmt/core.h"
#include <string>
using namespace std;
constexpr auto kDescription = R"(
Welcome to clumpy. This tool can process or generate large swaths of image
data. It is meant to be used in conjunction with Python.
)";
void help() {
auto& reg = ClumpyCommand::registry();
fmt::print("{}\n", kDescription);
fmt::print("{:20} {}\n", "help", "list all commands and their arguments");
fmt::print("{:20} {}\n", "examples", "print a usage example for each command");
for (auto r : reg) {
auto cmd = r.second();
fmt::print("{:20} {}\n", r.first, cmd->description());
if (not cmd->usage().empty()) {
fmt::print("{:20} usage: {} {}\n", "", r.first, cmd->usage());
}
delete cmd;
}
}
void examples() {
auto& reg = ClumpyCommand::registry();
for (auto r : reg) {
auto cmd = r.second();
fmt::print("clumpy {} {}\n", r.first, cmd->example());
delete cmd;
}
}
int main(const int argc, const char *argv[]) {
if (argc <= 1 || !strcmp(argv[1], "help")) {
help();
return 0;
}
if (!strcmp(argv[1], "examples")) {
examples();
return 0;
}
auto& reg = ClumpyCommand::registry();
auto iter = reg.find(argv[1]);
if (iter == reg.end()) {
help();
return 1;
}
auto cmd = iter->second();
vector<string> all_args;
for (int i = 2; i < argc; i++) {
all_args.emplace_back(argv[i]);
}
bool success = cmd->exec(all_args);
delete cmd;
return success ? 0 : 1;
}