-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cc
51 lines (45 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
#include <cstdio>
#include <algorithm>
#include "pkg/exec.h"
#include "pkg/load_deps.h"
#include "pkg/print_status.h"
namespace fs = boost::filesystem;
using namespace pkg;
extern bool verbose;
bool has_flag(int argc, char** argv, char const* str) {
return std::any_of(argv, argv + argc,
[&](char* arg) { return std::strcmp(arg, str) == 0; });
}
int main(int argc, char** argv) {
if (argc < 2 || has_flag(argc - 1, argv + 1, "--help") ||
has_flag(argc - 1, argv + 1, "-h")) {
printf(
"Usage:\n"
" pkg load | -l [clone dependencies]\n"
" -h for https (default: ssh);\n"
" -f for hard reset (default: checkout)]\n"
" -r for recursive (default: false)]\n"
" pkg status | -s [print status]\n"
"\n"
"Common flags - apply everywhere:\n"
" -v verbose [print what's going on]\n");
return 0;
}
try {
auto const mode = std::string_view{argv[1]};
set_verbose(has_flag(argc - 1, argv + 1, "-v"));
if (mode == "load" || mode == "-l") {
load_deps(fs::path{"."}, fs::path("deps"), //
has_flag(argc - 1, argv + 1, "-h"), //
has_flag(argc - 1, argv + 1, "-f"), //
has_flag(argc - 1, argv + 1, "-r"));
} else if (mode == "status" || mode == "-s") {
print_status(fs::path{"."}, fs::path("deps"));
} else {
fmt::print("Unknown mode {}. See pkg --help for usage.", mode);
}
} catch (std::exception const& e) {
std::cerr << "error: " << e.what() << "\n";
return 1;
}
}