-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharg_class.cpp
More file actions
86 lines (76 loc) · 2.08 KB
/
arg_class.cpp
File metadata and controls
86 lines (76 loc) · 2.08 KB
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
#include "arg_class.h"
/**
* @brief Metodo constructor
*
* @param Los argumentos del programa: int argc, char *argv[]
*/
Args::Args(int argc, char *argv[]) {
args = std::vector<std::string>(argv, argv + argc);
repo_path = std::filesystem::current_path().string();
if (argc == 1) {
cmd = "help";
return;
} else {
cmd = args[1].c_str();
}
auto it = std::find(args.begin(), args.end(), "--alen");
if (it != args.end()) {
it++;
abbrv_len = stoul(*it);
print_abbrv = true;
}
}
/**
* @brief Ejecuta un comando de acuerdo a los argumentos suministrados.
*
* @param No tiene parámetros.
*
* @return Retorna 0 en caso de exito, -1 en caso de error.
*/
int Args::run_cmd() {
int ret = 0;
if (strcmp(cmd, "help") == 0) {
usage();
return ret;
}
HashList hl(repo_path, abbrv_len);
if (strcmp(cmd, "stats") == 0) {
hl.repo_stats();
} else if (strcmp(cmd, "print") == 0) {
hl.print_hashes(print_abbrv);
} else if (strcmp(cmd, "hist") == 0) {
hl.histogram_calc();
} else if (strcmp(cmd, "hd") == 0) {
hl.hamming_calc(print_buf);
} else if (strcmp(cmd, "hdstats") == 0) {
hl.hamming_calc(hd_stats);
} else if (strcmp(cmd, "branch") == 0) {
std::string branch = hl.get_current_branch();
std::println("{}", branch);
} else {
std::println(stderr, "Command '{}' not found!", cmd);
std::print("");
usage();
ret = -1;
}
return ret;
}
/**
* @brief Imprime el texto de uso del programa en stdout
*
* @param No tiene parámetros.
*
* @return No retorna ningun valor o elemento.
*/
void Args::usage(void) {
std::string usage = "\nhdr\n"
"Uso: hdr cmd [--alen val]\n\n"
"$ cd <repo>\n\n"
"Obtener distancias de Hamming:\n"
"$ hdr hd [--alen <val>]\n\n"
"Obtener histograma:\n"
"$ hdr hist [--alen <val>]\n\n"
"Obtener minimo, maximo y valor medio:\n"
"$ hdr hdstats [--alen <val>]\n\n";
std::println("{}", usage);
}