-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.cpp
49 lines (40 loc) · 1.2 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
#include <glob/glob.h>
#include <glob/version.h>
#include <cxxopts.hpp>
#include <iostream>
#include <string>
int main(int argc, char** argv) {
cxxopts::Options options(argv[0], "Run glob to find all the pathnames matching a specified pattern");
bool recursive;
std::vector<std::string> patterns;
// clang-format off
options.add_options()
("h,help", "Show help")
("v,version", "Print the current version number")
("r,recursive", "Run glob recursively", cxxopts::value<bool>(recursive)->default_value("false"))
("i,input", "Patterns to match", cxxopts::value<std::vector<std::string>>(patterns))
;
// clang-format on
auto result = options.parse(argc, argv);
if (result["help"].as<bool>()) {
std::cout << options.help() << std::endl;
return 0;
} else if (result["version"].as<bool>()) {
std::cout << "glob, version " << GLOB_VERSION << std::endl;
return 0;
}
if (patterns.empty()) {
std::cout << options.help() << std::endl;
return 0;
}
if (recursive) {
for (auto& match: glob::rglob(patterns)) {
std::cout << match << "\n";
}
} else {
for (auto& match: glob::glob(patterns)) {
std::cout << match << "\n";
}
}
return 0;
}