added an option for printing paths
This commit is contained in:
parent
d1d060f5e9
commit
c688946c83
1 changed files with 25 additions and 3 deletions
28
main.cpp
28
main.cpp
|
|
@ -74,8 +74,9 @@ void show_help() {
|
||||||
ss << " -c --create_link : Create a new link e.g: goto --create_link [LINK_NAME] [FROM_PATH]" << std::endl;
|
ss << " -c --create_link : Create a new link e.g: goto --create_link [LINK_NAME] [FROM_PATH]" << std::endl;
|
||||||
ss << " -l --list : List all the existing links" << std::endl;
|
ss << " -l --list : List all the existing links" << std::endl;
|
||||||
ss << " -lo --links-only : List the name of the links only (This is mostly for autocompletion)." << std::endl;
|
ss << " -lo --links-only : List the name of the links only (This is mostly for autocompletion)." << std::endl;
|
||||||
ss << " -d --delete_link : Delete an exisiting link e.g: goto -d [LINK_NAME]" << std::endl;
|
ss << " -p --print-path : Prints the path of the specified link and exits. e.g: goto -p [LINK_NAME]" << std::endl;
|
||||||
ss << " -rf --delete_file : Delete the existing link file completely." << std::endl;
|
ss << " -d --delete-link : Delete an exisiting link e.g: goto -d [LINK_NAME]" << std::endl;
|
||||||
|
ss << " -rf --delete-file : Delete the existing link file completely." << std::endl;
|
||||||
ss << " [LINK_NAME] : Goes to an exisiting link e.g: goto [LINK_NAME]" << std::endl;
|
ss << " [LINK_NAME] : Goes to an exisiting link e.g: goto [LINK_NAME]" << std::endl;
|
||||||
ss << " [LINK_NAME] : Rules for creating [LINK_NAME] name must be BASH variable and must not start with \"-\"" << std::endl;
|
ss << " [LINK_NAME] : Rules for creating [LINK_NAME] name must be BASH variable and must not start with \"-\"" << std::endl;
|
||||||
ss << " [LINK_NAME] : [LINK_NAME] cannot be \"last\"" << std::endl;
|
ss << " [LINK_NAME] : [LINK_NAME] cannot be \"last\"" << std::endl;
|
||||||
|
|
@ -230,6 +231,18 @@ void delete_file() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void print_path(std::string link_name) {
|
||||||
|
QJsonObject config = globals::read_config().or_else([] (bool err){
|
||||||
|
std::cout << "Could not read conifg file." << std::endl;
|
||||||
|
exit(-1);
|
||||||
|
return std::expected<QJsonObject, bool> {QJsonObject()};
|
||||||
|
}).value();
|
||||||
|
std::string place = config[QString::fromStdString(link_name)].toString("Unkown link name.").toStdString();
|
||||||
|
std::cout << place << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
QCoreApplication::setApplicationName("goto");
|
QCoreApplication::setApplicationName("goto");
|
||||||
|
|
@ -241,7 +254,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
globals::config_path = globals::config_path / "links.json";
|
globals::config_path = globals::config_path / "links.json";
|
||||||
|
|
||||||
std::unordered_map<std::string, int> command_list = {{"help", 1}, {"h", 1}, {"create_link", 2}, {"c", 2}, {"l", 3}, {"list", 3}, {"d", 4}, {"delete_link", 4}, {"rf", 5}, {"delete_file", 5}, {"lo", 6}, {"links-only", 6}};
|
std::unordered_map<std::string, int> command_list = {{"help", 1}, {"h", 1}, {"create_link", 2}, {"c", 2}, {"l", 3}, {"list", 3}, {"d", 4}, {"delete-link", 4}, {"rf", 5}, {"delete-file", 5}, {"lo", 6}, {"links-only", 6}, {"p", 7}, {"--print-path", 7}};
|
||||||
|
|
||||||
|
|
||||||
int command_size = argc - 1;
|
int command_size = argc - 1;
|
||||||
|
|
@ -312,6 +325,15 @@ int main(int argc, char *argv[]) {
|
||||||
print_links_only();
|
print_links_only();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
case 7: {
|
||||||
|
if(command_size != 2) {
|
||||||
|
show_invalid();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
std::string link_name = argv[2];
|
||||||
|
print_path(link_name);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue