-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
77 lines (70 loc) · 2.19 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
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
#include <cassert>
#include <iostream>
#include <string>
#include "tag_export.h"
#define TAG2JSON_VERSION "1.0"
void PrintHelp() {
std::cout << "tag2json utility for import/export information about tags in the json format. Evgeny Kislov, 2024" << std::endl;
std::cout << "Usage:" << std::endl;
std::cout << " tag2json [-e tagfile jsonfile] [-i jsonfile tagfile] [-f] [--help|-h] [--version]" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << " -e tagfile jsonfile export tag information from tagvfs file to json file" << std::endl;
std::cout << " -i jsonfile tagfile import tag information from json file to tagvfs file" << std::endl;
std::cout << " -f force rewrite output file, without confirmation" << std::endl;
std::cout << " -h, --help show help and exit" << std::endl;
std::cout << " --version show version information and exit" << std::endl;
}
int main(int argc, char** argv) {
bool opt_force = false;
bool opt_export = false;
bool opt_import = false;
std::string opt_exp_src, opt_exp_dst;
std::string opt_imp_src, opt_imp_dst;
bool bad_cmd = false;
for (int i = 1; i < argc; ++i) {
std::string opt = argv[i];
if (opt == "-h" || opt == "--help") {
PrintHelp();
return 0;
} else if (opt == "--version") {
std::cout << TAG2JSON_VERSION << std::endl;
return 0;
} else if (opt == "-f") {
opt_force = true;
} else if (opt == "-e") {
if ((i + 2) < argc) {
opt_export = true;
opt_exp_src = argv[i + 1];
opt_exp_dst = argv[i + 2];
i += 2;
} else {
bad_cmd = true;
break;
}
} else if (opt == "-i") {
if ((i + 2) < argc) {
opt_import = true;
opt_imp_src = argv[i + 1];
opt_imp_dst = argv[i + 2];
i += 2;
} else {
bad_cmd = true;
break;
}
} else {
bad_cmd = true;
}
}
if (bad_cmd || (opt_export && opt_import) || !(opt_export || opt_import)) {
PrintHelp();
return 1;
}
if (opt_export) {
return TagExport(opt_exp_src, opt_exp_dst, opt_force);
}
if (opt_import) {
std::cerr << "Import isn't implemented yet" << std::endl;
}
assert(false);
return 1;
}