diff --git a/doc/manafiles.1 b/doc/manafiles.1 index d535072..0b71548 100644 --- a/doc/manafiles.1 +++ b/doc/manafiles.1 @@ -1,4 +1,4 @@ -.TH MANAFILES 1 "2022-01-29" "manafiles 0.5" "User Commands" +.TH MANAFILES 1 "2025-02-02" "manafiles 0.6" "User Commands" .SH NAME manafiles \- config file and package tracking utility @@ -31,7 +31,7 @@ See File Options below. .TP .BR \-P ", " \-\-package Operate on packages. \ -This operation allows you to track installed packages and reinstall them. \ +This operation allows tracking installed packages and reinstalling them. \ In the first case, if no package names are provided in the command line, all packages will be selected. \ See Package Options below. @@ -67,8 +67,10 @@ Install all AUR packages of the stored list. Install all official packages of the stored list. .TP -.BR \-s ", " \-\-store -Stores a list of all installed packages on the system. +.BR \-s ", " \-\-search +Search each locally-installed package for names via a partial match. \ +When including multiple search terms, all packages with names matching any of those terms are returned. \ +If the \fB-s\fR option is ommited, packages names are filtered via a full match. .SH EXAMPLES Usage examples: diff --git a/src/main.cpp b/src/main.cpp index cf6392f..bd24526 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Riyyi + * Copyright (C) 2021-2022,2025 Riyyi * * SPDX-License-Identifier: MIT */ @@ -8,11 +8,12 @@ #include #include +#include "ruc/argparser.h" +#include "ruc/timer.h" + #include "config.h" #include "dotfile.h" #include "package.h" -#include "ruc/argparser.h" -#include "ruc/timer.h" int main(int argc, const char* argv[]) { @@ -23,7 +24,7 @@ int main(int argc, const char* argv[]) bool addOrAur = false; bool install = false; bool pull = false; - bool pushOrStore = false; + bool pushOrSearch = false; bool verbose = false; std::vector targets {}; @@ -36,7 +37,7 @@ int main(int argc, const char* argv[]) argParser.addOption(addOrAur, 'a', "add", nullptr, nullptr); argParser.addOption(install, 'i', "install", nullptr, nullptr); argParser.addOption(pull, 'l', "pull", nullptr, nullptr); - argParser.addOption(pushOrStore, 's', "push", nullptr, nullptr); + argParser.addOption(pushOrSearch, 's', "push", nullptr, nullptr); argParser.addOption(verbose, 'v', "verbose", nullptr, nullptr); argParser.addArgument(targets, "targets", nullptr, nullptr, ruc::ArgParser::Required::No); @@ -60,32 +61,29 @@ int main(int argc, const char* argv[]) if (pull) { Dotfile::the().pull(targets); } - if (pushOrStore) { + if (pushOrSearch) { Dotfile::the().push(targets); } - if (!addOrAur && !pull && !pushOrStore) { + if (!addOrAur && !pull && !pushOrSearch) { Dotfile::the().list(targets); } } else if (packageOperation) { if (addOrAur) { - Package::the().aurInstall(); + Package::the().aurInstall(targets); } if (install) { - Package::the().install(); - } - if (pushOrStore) { - Package::the().store(); + Package::the().install(targets); } - if (!addOrAur && !install && !pushOrStore) { - Package::the().list(targets); + if (!addOrAur && !install) { + Package::the().list(targets, pushOrSearch); } } else if (helpOperation) { - // TODO open manpage + // TODO: open manpage } else { - // TODO open manpage + // TODO: open manpage } #ifndef NDEBUG diff --git a/src/package.cpp b/src/package.cpp index dd0a591..6127094 100644 --- a/src/package.cpp +++ b/src/package.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Riyyi + * Copyright (C) 2021-2022,2025 Riyyi * * SPDX-License-Identifier: MIT */ @@ -14,12 +14,12 @@ #include // getline #include -#include "machine.h" -#include "package.h" -#include "ruc/file.h" #include "ruc/shell.h" #include "ruc/system.h" +#include "machine.h" +#include "package.h" + Package::Package(s) { } @@ -30,17 +30,27 @@ Package::~Package() // ----------------------------------------- -void Package::aurInstall() +void Package::aurInstall(const std::vector& targets) { - installOrAurInstall(InstallType::AurInstall); + if (targets.size() > 1) { + fprintf(stderr, "\033[31;1mPackage:\033[0m only 1 file can be read packages from at a time\n"); + return; + } + + installOrAurInstall(InstallType::AurInstall, targets.size() != 0 ? targets.front() : PACKAGE_FILE); } -void Package::install() +void Package::install(const std::vector& targets) { - installOrAurInstall(InstallType::Install); + if (targets.size() > 1) { + fprintf(stderr, "\033[31;1mPackage:\033[0m only 1 file can be read packages from at a time\n"); + return; + } + + installOrAurInstall(InstallType::Install, targets.size() != 0 ? targets.front() : PACKAGE_FILE); } -void Package::list(const std::vector& targets) +void Package::list(const std::vector& targets, bool partialMatch) { auto packagesOrEmpty = getPackageList(); @@ -62,7 +72,7 @@ void Package::list(const std::vector& targets) std::string line; while (std::getline(stream, line)) { for (const auto& target : targets) { - if (line.find(target) != std::string::npos) { + if (line == target || (partialMatch && line.find(target) != std::string::npos)) { packages.append(line + '\n'); break; } @@ -72,20 +82,6 @@ void Package::list(const std::vector& targets) printf("%s", packages.c_str()); } -void Package::store() -{ - auto packagesOrEmpty = getPackageList(); - - if (!packagesOrEmpty.has_value()) { - return; - } - - auto packageFile = ruc::File::create("./packages"); - packageFile.clear(); - packageFile.append(packagesOrEmpty.value()); - packageFile.flush(); -} - // ----------------------------------------- std::optional Package::fetchAurHelper() @@ -105,7 +101,7 @@ std::optional Package::fetchAurHelper() return {}; } -void Package::installOrAurInstall(InstallType type) +void Package::installOrAurInstall(InstallType type, const std::string& file) { distroDetect(); distroDependencies(); @@ -129,12 +125,12 @@ void Package::installOrAurInstall(InstallType type) ruc::System $; if (m_distro == Distro::Arch) { // Grab everything off enabled official repositories that is in the list - auto repoList = $("pacman -Ssq") | $("grep -xf ./packages"); + auto repoList = $("pacman -Ssq") | $("grep -xf " + file); if (type == InstallType::AurInstall) { // Determine which packages in the list are from the AUR // NOTE: ruc::System does not support commands with newlines - auto aurList = ruc::Shell()("grep -vx '" + repoList.output() + "' ./packages"); + auto aurList = ruc::Shell()("grep -vx '" + repoList.output() + "' " + file); command = aurHelper.value() + " -Sy --devel --needed --noconfirm " + aurList.output(); } else { @@ -143,7 +139,7 @@ void Package::installOrAurInstall(InstallType type) } else if (m_distro == Distro::Debian) { // Grab everything off enabled official repositories that is in the list - auto repoList = $("apt-cache search .").cut(1, ' ') | $("grep -xf ./packages"); + auto repoList = $("apt-cache search .").cut(1, ' ') | $("grep -xf " + file); command = "apt install " + repoList.output(); } diff --git a/src/package.h b/src/package.h index 28aaabb..e4d01b8 100644 --- a/src/package.h +++ b/src/package.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Riyyi + * Copyright (C) 2021-2022,2025 Riyyi * * SPDX-License-Identifier: MIT */ @@ -13,6 +13,8 @@ #include "ruc/singleton.h" +#define PACKAGE_FILE "./packages" + class Package : public ruc::Singleton { public: Package(s); @@ -29,14 +31,13 @@ public: AurInstall, }; - void aurInstall(); - void install(); - void list(const std::vector& targets = {}); - void store(); + void aurInstall(const std::vector& targets = {}); + void install(const std::vector& targets = {}); + void list(const std::vector& targets = {}, bool partialMatch = false); private: std::optional fetchAurHelper(); - void installOrAurInstall(InstallType type); + void installOrAurInstall(InstallType type, const std::string& file); bool findDependency(const std::string& search); bool distroDetect();