Permit `--search=…` in `-Q` and `-S` to allow for e.g. `--search=-doc`

Message ID 04781d57-77ce-2530-cee7-9a13c8301332@kittens.ph
State Rejected, archived
Headers show
Series Permit `--search=…` in `-Q` and `-S` to allow for e.g. `--search=-doc` | expand

Commit Message

Fredrick Brennan Nov. 21, 2021, 1:50 a.m. UTC
Greetings pacman-dev:

Currently, pacman does not allow one to run `pacman -S --search=-doc`, 
because despite documentation saying `--search` takes `<regexp>`, 
actually it is implemented as using the targets to determine what to 
search for.

It is quite difficult to figure out how to carry out this search query, 
and needlessly so, though `--search '\\-doc'` does work.

The cumulative effect of the two attached patches fixes it, allowing an 
easier way to search for arbitrary strings which may conflict with 
command line options.

Comments

Andrew Gregory Nov. 21, 2021, 6:12 p.m. UTC | #1
On 11/20/21 at 08:50pm, Fredrick Brennan wrote:
> Greetings pacman-dev:
> 
> Currently, pacman does not allow one to run `pacman -S --search=-doc`,
> because despite documentation saying `--search` takes `<regexp>`, actually
> it is implemented as using the targets to determine what to search for.
> 
> It is quite difficult to figure out how to carry out this search query, and
> needlessly so, though `--search '\\-doc'` does work.
> 
> The cumulative effect of the two attached patches fixes it, allowing an
> easier way to search for arbitrary strings which may conflict with command
> line options.

The documentation for --search could use clarification, but this is
unnecessary.  pacman respects the standard option terminator --

pacman -Ss -- -doc

Patch

From 04aa99ea014f5c52bb59070c63c3989d17e35388 Mon Sep 17 00:00:00 2001
From: Fredrick Brennan <copypaste@kittens.ph>
Date: Fri, 19 Nov 2021 16:10:51 -0500
Subject: [PATCH 2/2] =?UTF-8?q?Permit=20`--search=3D=E2=80=A6`=20in=20`-Q`?=
 =?UTF-8?q?=20and=20`-S`?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Allows for e.g. `pacman -S --search=-doc`, right now difficult to
discover how to do (`pacman -S --search '\\-doc'`)

Signed-off-by: Fredrick Brennan <copypaste@kittens.ph>
---
 src/pacman/pacman.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index ed2d19b2..ee575602 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -563,6 +563,8 @@  static int parsearg_query(int opt)
 		case OP_SEARCH:
 		case 's':
 			config->op_q_search = 1;
+			if (optarg != NULL)
+				parsearg_util_addlist(&(pm_targets));
 			break;
 		case OP_UNREQUIRED:
 		case 't':
@@ -605,6 +607,10 @@  static void checkargs_query(int parse_err)
 		invalid_opt(config->op_q_owns, "--search", "--owns");
 		checkargs_query_display_opts("--search");
 		checkargs_query_filter_opts("--search");
+		if (alpm_list_count(pm_targets) == 0 && parse_err) {
+			pm_printf(ALPM_LOG_ERROR, "No targets and --search, did you mean to use --search=…?");
+			cleanup(1);
+		}
 	} else if(config->op_q_owns) {
 		invalid_opt(config->group, "--owns", "--groups");
 		checkargs_query_display_opts("--owns");
@@ -823,6 +829,8 @@  static int parsearg_sync(int opt)
 		case OP_SEARCH:
 		case 's':
 			config->op_s_search = 1;
+			if (optarg != NULL)
+				parsearg_util_addlist(&(pm_targets));
 			break;
 		case OP_SYSUPGRADE:
 		case 'u':
@@ -860,6 +868,10 @@  static void checkargs_sync(int parse_err)
 		invalid_opt(config->op_q_list, "--search", "--list");
 		invalid_opt(config->op_s_upgrade, "--search", "--sysupgrade");
 		invalid_opt(config->op_s_downloadonly, "--search", "--downloadonly");
+		if (alpm_list_count(pm_targets) == 0 && parse_err) {
+			pm_printf(ALPM_LOG_ERROR, "No targets and --search, did you mean to use --search=…?");
+			cleanup(1);
+		}
 	} else if(config->op_q_list) {
 		invalid_opt(config->group, "--list", "--groups");
 		invalid_opt(config->op_s_upgrade, "--list", "--sysupgrade");
@@ -914,7 +926,7 @@  static int parseargs(int argc, char *argv[])
 		{"root",       required_argument, 0, OP_ROOT},
 		{"sysroot",    required_argument, 0, OP_SYSROOT},
 		{"recursive",  no_argument,       0, OP_RECURSIVE},
-		{"search",     no_argument,       0, OP_SEARCH},
+		{"search",     optional_argument, 0, OP_SEARCH},
 		{"regex",      no_argument,       0, OP_REGEX},
 		{"machinereadable",      no_argument,       0, OP_MACHINEREADABLE},
 		{"unrequired", no_argument,       0, OP_UNREQUIRED},
-- 
2.34.0