minor bug fixes

This commit is contained in:
UnrealDragon 2025-09-15 01:21:33 +05:30
commit 72f4c3d7b8

View file

@ -78,8 +78,9 @@ void show_help() {
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] : 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 << "Reserved link names: " << std::endl;
ss << " last : Stores the last navigated link directory" << std::endl;
ss << " prev : Stores the directory from which last navigation was performed" << std::endl;
std::cout << ss.str();
}
@ -103,12 +104,16 @@ void print_links() {
int iter = 1;
std::cout << "Links from file: " << globals::config_path << std::endl;
for(auto &[key, value]: link_list) {
if(key != "last")
if(key != "last" && key != "prev")
std::cout << iter++ << ". " << key << " --> " << value << std::endl;
}
if(link_list.find("last") != link_list.end()) {
std::cout << iter << ". Last place --> " << link_list["last"] << std::endl;
std::cout << iter++ << ". last --> " << link_list["last"] << std::endl;
}
if(link_list.find("prev") != link_list.end()) {
std::cout << iter++ << ". prev --> " << link_list["prev"] << std::endl;
}
}
void print_links_only() {
@ -130,14 +135,19 @@ void print_links_only() {
void delete_link(std::string link_name) {
QJsonObject obj = globals::read_config().or_else([](bool err){
QJsonObject obj = globals::read_config().or_else([](bool err) {
std::cout << "Could not read config file." << std::endl;
exit(-1);
return std::expected<QJsonObject, bool> {QJsonObject()};
}).value();
if(obj.find(QString::fromStdString(link_name)) != obj.end()) {
obj.remove(QString::fromStdString(link_name));
globals::overwrite_config(obj);
std::cout << "Link: " << link_name << " deleted." << std::endl;
}
else {
std::cout << "Link: " << link_name << " does not exist in the links file." << std::endl;
}
}
void create_link(std::string link_name, std::string dir) {
@ -192,6 +202,7 @@ void goto_link(std::string link_name) {
std::cout << "Specified link: " << link_name << " does not exist in links file." << std::endl;
exit(-1);
}
config["prev"] = QString::fromStdString(std::filesystem::current_path().string());
config["last"] = QString::fromStdString(place);
globals::overwrite_config(config);
// int parent_id = get_parent_id();
@ -238,7 +249,7 @@ void print_path(std::string link_name) {
exit(-1);
return std::expected<QJsonObject, bool> {QJsonObject()};
}).value();
std::string place = config[QString::fromStdString(link_name)].toString("Unkown link name.").toStdString();
std::string place = config[QString::fromStdString(link_name)].toString("Unknown link name.").toStdString();
std::cout << place << std::endl;
}
@ -254,7 +265,7 @@ int main(int argc, char *argv[]) {
}
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}, {"p", 7}, {"--print-path", 7}};
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;