From 49ae2f00e149f518e334b48e6ea77b24c7c28ece Mon Sep 17 00:00:00 2001 From: Toni500github Date: Mon, 11 Mar 2024 18:24:31 +0100 Subject: [PATCH] sanitize config value + print sync's db name near the name --- include/taur.hpp | 7 +++++++ src/config.cpp | 6 +++--- src/taur.cpp | 27 ++++++++++++++++++--------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/include/taur.hpp b/include/taur.hpp index bdc8801..06c728c 100644 --- a/include/taur.hpp +++ b/include/taur.hpp @@ -29,6 +29,13 @@ struct TaurPkg_t { string version; string url; vector depends = vector(); + string db_name; +}; + +struct db_colors { + const string extra = BOLDMAGENTA; + const string multilib = BOLDCYAN; + const string core = BOLDYELLOW; }; class TaurBackend { diff --git a/src/config.cpp b/src/config.cpp index 1cb0858..517c3aa 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -67,10 +67,10 @@ void Config::loadConfigFile(string filename) { exit(-1); } - this->sudo = this->getConfigValue("general.sudo", "sudo"); + this->sudo = this->getConfigValue("general.sudo", "sudo"); sanitizeStr(this->sudo); this->useGit = this->getConfigValue("general.useGit", true); this->aurOnly = this->getConfigValue("general.aurOnly", false); - this->makepkgBin = this->getConfigValue("bins.makepkgBin", "makepkg"); - this->cacheDir = this->getCacheDir(); + this->makepkgBin = this->getConfigValue("bins.makepkgBin", "makepkg"); sanitizeStr(this->makepkgBin); + this->cacheDir = this->getCacheDir(); sanitizeStr(this->cacheDir); this->colors = this->getConfigValue("general.colors", true); } diff --git a/src/taur.cpp b/src/taur.cpp index 4729686..6a87cef 100644 --- a/src/taur.cpp +++ b/src/taur.cpp @@ -425,17 +425,25 @@ vector TaurBackend::getPkgFromJson(rapidjson::Document& doc, bool useGit vector TaurBackend::search_pac(string query) { sanitizeStr(query); - string cmd = "pacman -Qn | grep \"" + query + "\""; + // we search for the package name and print only the name, not the description + string cmd = "pacman -Ss \"" + query + "\" | awk '{if (NR % 2 != 0) print $0}'"; vector pkgs_string = split(exec(cmd), '\n'); - + TaurPkg_t taur_pkg; vector out; for (size_t i = 0; i < pkgs_string.size(); i++) { try { - vector pkg = split(pkgs_string[i], ' '); - out.push_back((TaurPkg_t) { pkg[0], pkg[1], "" }); + vector pkg = split(pkgs_string[i], '/'); + size_t space_pos = pkg[1].find(' '); + pkg[1].erase(space_pos); + taur_pkg.name = pkg[1]; + taur_pkg.db_name = pkg[0]; + std::cout << "pkg0: "< TaurBackend::search(string query, bool useGit) { for (int i = 0; i < aurPkgs.size(); i++) std::cout - << BOLDBLUE << "[" << i << "]: " - << NOCOLOR << BOLD << "AUR/" << aurPkgs[i] + << MAGENTA << i << " " + << NOCOLOR << BOLDBLUE << "aur/" << BOLD << aurPkgs[i] << NOCOLOR << std::endl; for (int i = 0; i < pacPkgs.size(); i++) std::cout - << BOLDCYAN << "[" << i + aurPkgs.size() << "]: " - << NOCOLOR << BOLD << "SYNC/" << pacPkgs[i].name + << MAGENTA << i + aurPkgs.size() << " " + << BOLDMAGENTA << pacPkgs[i].db_name << '/' << BOLD << pacPkgs[i].name + << " " << BOLDGREEN << pacPkgs[i].version << NOCOLOR << std::endl;