Skip to content

Commit

Permalink
Few things
Browse files Browse the repository at this point in the history
* add more infos for the user
* print only AUR packages when asked which to review/cleanbuild
* added multi-install for both system and AUR pkgs (1st AUR ones, then system)
  • Loading branch information
Toni500github committed Apr 30, 2024
1 parent 707eb2d commit 5621922
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
11 changes: 7 additions & 4 deletions include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ string makepkg_list(string const& pkg_name, string con
void free_list_and_internals(alpm_list_t *list);
fmt::text_style getColorFromDBName(string_view db_name);
vector<alpm_pkg_t *> filterAURPkgs(vector<alpm_pkg_t *> pkgs, alpm_list_t *syncdbs, bool inverse);
vector<string_view> filterAURPkgsNames(vector<string_view> pkgs, alpm_list_t *syncdbs, bool inverse);
string shell_exec(string_view cmd);
vector<string> split(string_view text, char delim);
fmt::rgb hexStringToColor(string_view hexstr);
Expand Down Expand Up @@ -261,12 +262,14 @@ bool askUserYorN(bool def, prompt_yn pr, Args&&... args) {
*/
template <typename T, typename = std::enable_if_t<is_fmt_convertible_v<T>>>
vector<T> askUserForList(vector<T> &list, prompt_list pr, bool required = false) {
string sep_str = "Type the index of each package (e.g 4 12 2)";
string sep_str = "Type the index of each package (eg: \"0 1 2\", \"0-2\", \"*\" for all, \"n\" for none)";
string result_str;

for (size_t i = 0; i < list.size(); i++)
fmt::println(fmt::fg(color.index), "[{}] {}", i, fmt::format(BOLD | fmt::fg(fmt::color::white), "{}", list[i]));


log_println(INFO, "{}", sep_str);

switch (pr) {
case PROMPT_LIST_CLEANBUILDS:
log_printf(INFO, BOLD, "Packages to completely rebuild: ");
Expand All @@ -290,7 +293,7 @@ vector<T> askUserForList(vector<T> &list, prompt_list pr, bool required = false)

while (std::getline(std::cin, result_str)) {

if (result_str.empty() && !required) {
if ((result_str.empty() && !required) || result_str == "n") {
std::cout << std::endl;
return {};
}
Expand All @@ -304,7 +307,7 @@ vector<T> askUserForList(vector<T> &list, prompt_list pr, bool required = false)
bool breakandcontinue = false;
for (size_t i = 0; i < input_indices.size() && !breakandcontinue; i++) {
// 1-5 means 1 through 5
if (input_indices[i].find('-') != std::string::npos) {
if (input_indices[i].find('-') != string::npos) {
vector<string> loop_bounds = split(input_indices[i], '-');
if (loop_bounds.size() != 2 || !is_numerical(loop_bounds[0]) || !is_numerical(loop_bounds[1])) {
log_printf(WARN, "Invalid loop range! (loop ranges look like \"0-5\"): ");
Expand Down
23 changes: 13 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ int installPkg(alpm_list_t *pkgNames) {
bool returnStatus = true;

vector<string> pacmanPkgs; // list of pacman packages to install, to avoid spamming pacman.
vector<string_view> pkgNamesVec;
vector<string_view> pkgNamesVec, aurPkgNamesVec;

if (op.op_s_upgrade) {
if (!config->aurOnly) {
Expand All @@ -156,15 +156,17 @@ int installPkg(alpm_list_t *pkgNames) {
if (pkgNamesVec.empty())
return false;

aurPkgNamesVec = filterAURPkgsNames(pkgNamesVec, alpm_get_syncdbs(config->handle), true);

vector<string_view> pkgNamesToCleanBuild, pkgNamesToReview;

if (!op.op_s_search) {
if (!op.op_s_cleanbuild)
pkgNamesToCleanBuild = askUserForList<string_view>(pkgNamesVec, PROMPT_LIST_CLEANBUILDS);
pkgNamesToCleanBuild = askUserForList<string_view>(aurPkgNamesVec, PROMPT_LIST_CLEANBUILDS);
else
pkgNamesToCleanBuild = {};

pkgNamesToReview = askUserForList<string_view>(pkgNamesVec, PROMPT_LIST_REVIEWS);
pkgNamesToReview = askUserForList<string_view>(aurPkgNamesVec, PROMPT_LIST_REVIEWS);
}

for (size_t i = 0; i < pkgNamesVec.size(); i++) {
Expand Down Expand Up @@ -262,15 +264,16 @@ int installPkg(alpm_list_t *pkgNames) {
returnStatus = false;
continue;
}

log_println(DEBUG, "Installing {}.", pkg.name);
if (!pacman_exec("-U", split(built_pkg, ' '), false)) {
log_println(ERROR, "Failed to install {}.", pkg.name);
returnStatus = false;
continue;
}
pkgs_to_install += built_pkg + ' ';
}
}

log_println(DEBUG, "Installing {}", fmt::join(pkgNamesVec, " "));
pkgs_to_install.erase(pkgs_to_install.length()-1);
if (!pacman_exec("-U", split(pkgs_to_install, ' '), false)) {
log_println(ERROR, "Failed to install {}.", fmt::join(pkgNamesVec, " "));
returnStatus = false;
}

if (!pacmanPkgs.empty()) {
string op_s = "-S";
Expand Down
26 changes: 26 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ bool makepkg_exec(string_view cmd, bool exitOnFailure) {

if (config->noconfirm)
ccmd.push_back("--noconfirm");

if (!config->colors)
ccmd.push_back("--nocolor");

Expand Down Expand Up @@ -491,6 +492,31 @@ vector<alpm_pkg_t *> filterAURPkgs(vector<alpm_pkg_t *> pkgs, alpm_list_t *syncd
return out;
}

/** Filters out/only AUR packages (names only).
* Default behavior is filtering out.
* @param pkgs a unique_ptr to a list of packages to filter.
* @param inverse a bool that, if true, will return only AUR packages instead of the other way around.
* @return an optional unique_ptr to a result.
*/
vector<string_view> filterAURPkgsNames(vector<string_view> pkgs, alpm_list_t *syncdbs, bool inverse) {
vector<string_view> out;

for (; syncdbs; syncdbs = syncdbs->next) {
for (size_t i = 0; i < pkgs.size(); i++) {
bool existsInSync = alpm_db_get_pkg((alpm_db_t *)(syncdbs->data), pkgs[i].data()) != nullptr;

if ((existsInSync && inverse) || (!existsInSync && !inverse))
pkgs[i] = "";
}
}

for (size_t i = 0; i < pkgs.size(); i++)
if (pkgs[i].length())
out.push_back(pkgs[i]);

return out;
}

string getTitleFromVotes(float votes) {
if (votes < 2)
return "Untrustable";
Expand Down

0 comments on commit 5621922

Please sign in to comment.