Skip to content

Commit

Permalink
Added noaur flag
Browse files Browse the repository at this point in the history
  • Loading branch information
al1-ce committed May 8, 2023
1 parent 7b4b934 commit ab95442
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/pkm/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import sily.path: fixPath;
// stats | yay -Ps
// pkgbuild | yay -G term | yay -Gp term

private const string _version = "pkm v1.1.4";
private const string _version = "pkm v1.2.1";

int main(string[] args) {
version (Windows) {
Expand All @@ -45,12 +45,14 @@ int main(string[] args) {

bool optVersion = false;
bool optAur = false;
bool optNoAur = false;

auto help = getopt(
args,
config.bundling, config.passThrough,
config.bundling, config.passThrough, config.caseSensitive,
"version", "print version", &optVersion,
"aur|a", "search only aur", &optAur
"aur|a", "search only aur (yay --aur)", &optAur,
"noaur|A", "search only official (only custom search)", &optNoAur
);

string[] configPath = [
Expand Down Expand Up @@ -110,7 +112,7 @@ int main(string[] args) {
printGetopt("pkm <operation> [...]",
"Options", help.options, "Commands", commands
);
}
}
return 0;
}

Expand Down Expand Up @@ -179,7 +181,7 @@ int main(string[] args) {
if (conf.yaysearch) {
return wait(spawnProcess([yay, "-Ss"] ~ ops));
} else {
return search(yay, ops, conf);
return search(yay, ops, conf, optNoAur);
}
case "list":
return wait(spawnProcess([yay, "-Q"]));
Expand Down
13 changes: 6 additions & 7 deletions src/pkm/search.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private auto reg = regex(
r"(?:\s\((Orphaned)\))?(?:\s\(Out-of-date:\s(.*?)\))?" ~
r"(?:\s\((Installed)(?:\:\s(.*?))?\))?(?:\s{6}|\s{5})(.*)(?:\r|\n|\z)", "gm");

int search(string yay, string[] terms, SearchConfig conf) {
int search(string yay, string[] terms, SearchConfig conf, bool noAur) {
// string yay = "/usr/bin/yay";
string tmpFile = tempDir ~ "/" ~ "pkm-yay-search-output.txt";
tmpFile = tmpFile.fixPath;
Expand All @@ -44,7 +44,7 @@ int search(string yay, string[] terms, SearchConfig conf) {
return pidErr;
}

printPackages(tmpFile, terms, conf);
printPackages(tmpFile, terms, conf, noAur);

remove(tmpFile);

Expand All @@ -56,7 +56,7 @@ int search(string yay, string[] terms, SearchConfig conf) {
// repo/name version (size|aur-votes) [group]? (orphaned)
// 7 8 9 10
// (outofdate) (installed: (version)) \n (description)
void printPackages(string tmpFile, string[] searchTerms, SearchConfig conf) {
void printPackages(string tmpFile, string[] searchTerms, SearchConfig conf, bool noAur) {
string contents = readText(tmpFile);

Pkg[] pkgs = [];
Expand All @@ -68,13 +68,14 @@ void printPackages(string tmpFile, string[] searchTerms, SearchConfig conf) {
if (pkg.length != 11) {

writelncol(FG.ltred, true, "Error: search regex is not compatible with chosen package manager.");
goto noprint;
return;
}

string pkgsize;
string inssize;

if (pkg[1] == "aur") {
if (noAur) continue;
string[] _size = pkg[4].split(' ');
pkgsize = _size[0];
inssize = _size[1];
Expand Down Expand Up @@ -116,8 +117,6 @@ void printPackages(string tmpFile, string[] searchTerms, SearchConfig conf) {
printPackage(pkg, conf.color);
if (!print_) print_ = true;
}

noprint:
}

void printPackage(Pkg pkg, bool color) {
Expand Down Expand Up @@ -244,4 +243,4 @@ void writelncol(FG col, bool enabled, string args) {
} else {
write(args ~ "\n");
}
}
}

0 comments on commit ab95442

Please sign in to comment.