-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhere_is.cpp
79 lines (66 loc) · 3.4 KB
/
where_is.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
78
79
#include "where_is.hpp"
int main(int argc, char const *argv[]){
std::string name_file, name_folder, path;
if(argc < 2){
printf("%sUse %s or %s to get info about this program!\n", clt::fg_bright_red("[ERROR]: ").c_str(), clt::fg_bright_green("-h").c_str(), clt::fg_bright_blue("--help").c_str());
return 0;
} else{
for(int i = 0; i < argc; i++){
if(std::string(argv[i]) == "-h" || std::string(argv[i]) == "--help"){
printf("\n\tUseful information about program:\n\n");
printf("\t %s | %s\t\t\t-\tUseful information about program\n", clt::fg_bright_green("-h").c_str(), clt::fg_bright_blue("--help").c_str());
printf("\t %s | %s\t\t\t-\tFind file (use this with file extension for example file.pdf)\n", clt::fg_bright_green("-fl").c_str(), clt::fg_bright_blue("--file").c_str());
printf("\t %s | %s\t\t\t-\tFind folder (enter name folder)\n", clt::fg_bright_green("-fd").c_str(), clt::fg_bright_blue("--folder").c_str());
printf("\t %s | %s\t\t\t-\tChanging path which will be use for find file/folder (default use \"/\")\n\n", clt::fg_bright_green("-p").c_str(), clt::fg_bright_blue("--path").c_str());
return 0;
} else if(std::string(argv[i]) == "-fl" || std::string(argv[i]) == "--file"){
if(!std::string(argv[i + 1]).empty()){
name_file = std::string(argv[i + 1]);
} else{
printf("%sYou must enter name of file which you would like find!\n", clt::fg_bright_red("[ERROR]: ").c_str());
return 0;
}
} else if(std::string(argv[i]) == "-fd" || std::string(argv[i]) == "--folder"){
if(!std::string(argv[i + 1]).empty()){
name_folder = std::string(argv[i + 1]);
} else{
printf("%sYou must enter name of folder which you would like find!\n", clt::fg_bright_red("[ERROR]: ").c_str());
return 0;
}
} else if(std::string(argv[i]) == "-p" || std::string(argv[i]) == "--path"){
if(!std::string(argv[i + 1]).empty()){
path = std::string(argv[i + 1]);
} else{
path = MAIN_PATH;
}
}
}
if(name_file != ""){
if(path != ""){
whereis::find_file(name_file, path, [](const std::string &path_view){
printf("%s\n", clt::fg_bright_magenta(path_view).c_str());
});
return 0;
} else{
whereis::find_file(name_file, MAIN_PATH, [](const std::string &path_view){
printf("%s\n", clt::fg_bright_magenta(path_view).c_str());
});
return 0;
}
}
if(name_folder != ""){
if(path != ""){
whereis::find_folder(name_folder, path, [](const std::string &path_view){
printf("%s\n", clt::fg_bright_magenta(path_view).c_str());
});
return 0;
} else{
whereis::find_folder(name_folder, MAIN_PATH, [](const std::string &path_view){
printf("%s\n", clt::fg_bright_magenta(path_view).c_str());
});
return 0;
}
}
}
return 0;
}