public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage-utils:master commit in: man/, man/include/, /
Date: Sun, 14 Jul 2019 13:31:33 +0000 (UTC)	[thread overview]
Message-ID: <1563111006.26b9374ee23d16b3957b6ebc0cd80f53b22a4d16.grobian@gentoo> (raw)

commit:     26b9374ee23d16b3957b6ebc0cd80f53b22a4d16
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 14 13:30:06 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Jul 14 13:30:06 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=26b9374e

quse: add -F argument, move some -v functionality to -D

-v now controls default atom formatting, as with other applets, the
ability to list USE-flags, their state and description per package now
is enabled by the -D (describe) flag, which incidentally also makes more
sense.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 man/include/quse.optdesc.yaml | 11 +++---
 man/quse.1                    | 14 ++++---
 quse.c                        | 85 ++++++++++++++++++++++++-------------------
 3 files changed, 62 insertions(+), 48 deletions(-)

diff --git a/man/include/quse.optdesc.yaml b/man/include/quse.optdesc.yaml
index 693aade..71fcd2d 100644
--- a/man/include/quse.optdesc.yaml
+++ b/man/include/quse.optdesc.yaml
@@ -1,10 +1,11 @@
 exact: Search for exact string, e.g.\ do not use regular expression matching.
 verbose: |
-    Show descriptions for USE-flags for packages that match the search.
+    Show versions for packages that match the search.
     Also shows problems encountered during parsing.  These are mostly
     diagnostic and indicate possible incorrectness in the results.
 quiet: Ignored for compatibility with other qapplets.
-installed: |
-    Only search installed packages.  Together with \fB-v\fR this shows
-    USE-flags and their descriptions, and currently enabled flags
-    prefixed with an asterisk (\fI*\fR).
+describe: |
+    Describe the USE flag, when no USE-flag given and combined with
+    \fB-p\fR, lists all USE-flags with their descriptions (and enabled
+    state prefixed with an asterisk when used with \fB-I\fR) per
+    package.

diff --git a/man/quse.1 b/man/quse.1
index a30e189..8306ca5 100644
--- a/man/quse.1
+++ b/man/quse.1
@@ -20,12 +20,13 @@ List all ebuilds, don't match anything.
 Use the LICENSE vs IUSE.
 .TP
 \fB\-D\fR, \fB\-\-describe\fR
-Describe the USE flag.
+Describe the USE flag, when no USE-flag given and combined with
+\fB-p\fR, lists all USE-flags with their descriptions (and enabled
+state prefixed with an asterisk when used with \fB-I\fR) per
+package.
 .TP
 \fB\-I\fR, \fB\-\-installed\fR
-Only search installed packages.  Together with \fB-v\fR this shows
-USE-flags and their descriptions, and currently enabled flags
-prefixed with an asterisk (\fI*\fR).
+Only search installed packages.
 .TP
 \fB\-p\fR \fI<arg>\fR, \fB\-\-package\fR \fI<arg>\fR
 Restrict matching to package or category.
@@ -33,11 +34,14 @@ Restrict matching to package or category.
 \fB\-R\fR, \fB\-\-repo\fR
 Show repository the ebuild originates from.
 .TP
+\fB\-F\fR \fI<arg>\fR, \fB\-\-format\fR \fI<arg>\fR
+Print matched atom using given format string.
+.TP
 \fB\-\-root\fR \fI<arg>\fR
 Set the ROOT env var.
 .TP
 \fB\-v\fR, \fB\-\-verbose\fR
-Show descriptions for USE-flags for packages that match the search.
+Show versions for packages that match the search.
 Also shows problems encountered during parsing.  These are mostly
 diagnostic and indicate possible incorrectness in the results.
 .TP

diff --git a/quse.c b/quse.c
index bc99c3b..df8626e 100644
--- a/quse.c
+++ b/quse.c
@@ -27,7 +27,7 @@
 #include "xarray.h"
 #include "xregex.h"
 
-#define QUSE_FLAGS "eaLDIp:R" COMMON_FLAGS
+#define QUSE_FLAGS "eaLDIp:RF:" COMMON_FLAGS
 static struct option const quse_long_opts[] = {
 	{"exact",     no_argument, NULL, 'e'},
 	{"all",       no_argument, NULL, 'a'},
@@ -36,6 +36,7 @@ static struct option const quse_long_opts[] = {
 	{"installed", no_argument, NULL, 'I'},
 	{"package",    a_argument, NULL, 'p'},
 	{"repo",      no_argument, NULL, 'R'},
+	{"format",     a_argument, NULL, 'F'},
 	COMMON_LONG_OPTS
 };
 static const char * const quse_opts_help[] = {
@@ -46,6 +47,7 @@ static const char * const quse_opts_help[] = {
 	"Only search installed packages",
 	"Restrict matching to package or category",
 	"Show repository the ebuild originates from",
+	"Print matched atom using given format string",
 	COMMON_OPTS_HELP
 };
 #define quse_usage(ret) usage(ret, QUSE_FLAGS, quse_long_opts, quse_opts_help, NULL, lookup_applet_idx("quse"))
@@ -61,9 +63,10 @@ struct quse_state {
 	bool do_licence:1;
 	bool do_installed:1;
 	bool do_list:1;
-	bool do_repo:1;
+	bool need_full_atom:1;
 	depend_atom *match;
 	regex_t *pregv;
+	const char *fmt;
 };
 
 static char *_quse_getline_buf = NULL;
@@ -142,9 +145,8 @@ quse_search_use_local_desc(int portdirfd, struct quse_state *state)
 				if (state->do_list) {
 					state->retv[i] = xstrdup(q);
 				} else {
-					printf("%s%s/%s%s%s[%s%s%s] %s\n",
-							BOLD, atom->CATEGORY,
-							BLUE, atom->PN, NORM,
+					printf("%s[%s%s%s] %s\n",
+							atom_format(state->fmt, atom),
 							MAGENTA, p, NORM, q);
 				}
 			}
@@ -424,7 +426,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	int cnt;
 	int portdirfd = -1;  /* pacify compiler */
 
-	if (state->match || verbose) {
+	if (state->match || state->do_describe) {
 		atom = tree_get_atom(pkg_ctx, 0);
 		if (atom == NULL)
 			return 0;
@@ -471,7 +473,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 		free(s);
 	}
 
-	if (verbose) {
+	if (state->do_describe) {
 		portdirfd = openat(pkg_ctx->cat_ctx->ctx->portroot_fd,
 				state->overlay == NULL ? main_overlay : state->overlay,
 				O_RDONLY | O_CLOEXEC | O_PATH);
@@ -487,7 +489,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	v = buf;
 	w = buf + sizeof(buf);
 
-	if (state->do_all && !verbose) {
+	if (state->do_all && !state->do_describe) {
 		match = true;
 		v = q;
 	} else {
@@ -546,18 +548,10 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	}
 
 	if (match) {
-		const char *qfmt;
-
-		atom = tree_get_atom(pkg_ctx, state->do_repo);
-		if (state->do_repo) {
-			qfmt = "%[CATEGORY]%[PF]%[REPO]";
-		} else {
-			qfmt = "%[CATEGORY]%[PF]";
-		}
-
+		atom = tree_get_atom(pkg_ctx, state->need_full_atom);
 		if (quiet) {
-			printf("%s\n", atom_format(qfmt, atom));
-		} else if (verbose && !state->do_licence) {
+			printf("%s\n", atom_format(state->fmt, atom));
+		} else if (state->do_describe && !state->do_licence) {
 			/* multi-line result, printing USE-flags with their descs */
 			size_t desclen;
 			struct quse_state us = {
@@ -571,7 +565,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 				.overlay = NULL,
 			};
 
-			printf("%s\n", atom_format(qfmt, atom));
+			printf("%s\n", atom_format(state->fmt, atom));
 
 			q = p = meta->IUSE;
 			buf[0] = '\0';
@@ -654,7 +648,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 			free(us.retv);
 			free(us.argv);
 		} else {
-			printf("%s: %s\n", atom_format(qfmt, atom), v);
+			printf("%s: %s\n", atom_format(state->fmt, atom), v);
 		}
 	}
 
@@ -668,7 +662,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 		if (use != NULL)
 			free_set(use);
 	}
-	if (verbose)
+	if (state->do_describe)
 		close(portdirfd);
 
 	return EXIT_SUCCESS;
@@ -681,25 +675,27 @@ int quse_main(int argc, char **argv)
 	const char *overlay;
 	char *match = NULL;
 	struct quse_state state = {
-		.do_all = false,
-		.do_regex = true,
-		.do_describe = false,
-		.do_licence = false,
-		.do_installed = false,
-		.do_repo = false,
-		.match = NULL,
-		.overlay = NULL,
+		.do_all         = false,
+		.do_regex       = true,
+		.do_describe    = false,
+		.do_licence     = false,
+		.do_installed   = false,
+		.need_full_atom = false,
+		.match          = NULL,
+		.overlay        = NULL,
+		.fmt            = NULL,
 	};
 
 	while ((i = GETOPT_LONG(QUSE, quse, "")) != -1) {
 		switch (i) {
-		case 'e': state.do_regex = false;    break;
-		case 'a': state.do_all = true;       break;
-		case 'L': state.do_licence = true;   break;
-		case 'D': state.do_describe = true;  break;
-		case 'I': state.do_installed = true; break;
-		case 'R': state.do_repo = true;      break;
-		case 'p': match = optarg;            break;
+		case 'e': state.do_regex = false;      break;
+		case 'a': state.do_all = true;         break;
+		case 'L': state.do_licence = true;     break;
+		case 'D': state.do_describe = true;    break;
+		case 'I': state.do_installed = true;   break;
+		case 'p': match = optarg;              break;
+		case 'F': state.fmt = optarg;          /* fall through */
+		case 'R': state.need_full_atom = true; break;
 		COMMON_GETOPTS_CASES(quse)
 		}
 	}
@@ -727,7 +723,20 @@ int quse_main(int argc, char **argv)
 			xregcomp(&state.pregv[i], state.argv[i], REG_EXTENDED | REG_NOSUB);
 	}
 
-	if (state.do_describe) {
+	if (state.fmt == NULL) {
+		if (state.need_full_atom)
+			if (verbose)
+				state.fmt = "%[CATEGORY]%[PF]%[REPO]";
+			else
+				state.fmt = "%[CATEGORY]%[PN]%[REPO]";
+		else
+			if (verbose)
+				state.fmt = "%[CATEGORY]%[PF]";
+			else
+				state.fmt = "%[CATEGORY]%[PN]";
+	}
+
+	if (state.do_describe && state.match == NULL) {
 		array_for_each(overlays, n, overlay)
 			quse_describe_flag(portroot, overlay, &state);
 	} else if (state.do_installed) {


             reply	other threads:[~2019-07-14 13:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-14 13:31 Fabian Groffen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-05-16 14:30 [gentoo-commits] proj/portage-utils:master commit in: man/, man/include/, / Fabian Groffen
2019-05-13 12:57 Fabian Groffen
2019-02-05 13:51 Fabian Groffen
2018-04-12 19:33 Fabian Groffen
2018-04-03 11:50 Fabian Groffen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1563111006.26b9374ee23d16b3957b6ebc0cd80f53b22a4d16.grobian@gentoo \
    --to=grobian@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox