-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
50 lines (42 loc) · 1.13 KB
/
main.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
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include "lpm/types.h"
#include "lpm/macros.h"
#include "command.h"
#include "args.h"
#include "argparser.h"
#include "static/messages.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
LPM_PRINT(MESSAGES_HELP << "\n");
return 1;
}
std::string command = argv[1];
args_t args = ArgParser::parse(argc, argv, 2);
// Manually parse obligatory arguments.
if (
command == "add" ||
command == "remove" ||
command == "show"
) {
if (argc < 3) {
LPM_PRINT_ERROR("Missing argument: package_name" << "\n");
LPM_PRINT(MESSAGES_HELP << "\n");
return 1;
}
args["package_name"] = argv[2];
}
Command::Type command_type = ArgParser::validate(command, args, LPM_VALID_ARGS);
if (
command_type == Command::Type::UNKNOWN ||
command_type == Command::Type::HELP
) {
LPM_PRINT(MESSAGES_HELP << "\n");
return command_type < 0 ? 1 : 0;
}
if (!Command::execute(command_type, args)) {
return 1;
}
}