-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
58 lines (52 loc) · 1.58 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
#include <iostream>
#include <cassert>
#include <cstring>
#include "./cli/init/init.h"
#include "./cli/log/log.h"
#include "./cli/status/status.h"
#include "./cli/commit/commit.h"
#include "./cli/revert/revert.h"
#include "./cli/checkout/checkout.h"
struct Command {
const char* name;
void (*exec)(int, char**);
};
static bool areEqual(const char* str1, const char* str2) {
assert(str1);
assert(str2);
return !std::strcmp(str1, str2);
}
static void seeHelp() {
std::cout << " See 'line help' for list of avalible line commands. See 'line help <command>' for more info about a given line command." << std::endl;
}
int main(int argc, char** argv) {
const unsigned int commandsCount = 6;
Command commands[commandsCount] = {
{"init", line::cli::init},
{"log", line::cli::log},
{"status", line::cli::status},
{"commit", line::cli::commit},
{"revert", line::cli::revert},
{"checkout", line::cli::checkout}
};
void (*command)(int, char**) = nullptr;
if(argc == 1) {
std::cout << "line expects at least one argument. The command to execute.";
seeHelp();
return 0;
} else {
for(unsigned int i = 0; i < commandsCount; ++i) {
if(areEqual(argv[1], commands[i].name)) {
command = commands[i].exec;
break;
}
}
if(command) {
command(argc - 2, argv + 2);
} else {
std::cout << '\'' << "line " << argv[1] << '\'' << " is not a line command.";
seeHelp();
}
}
return 0;
}