diff options
author | Fabian Groffen <grobian@gentoo.org> | 2019-05-05 22:04:40 +0200 |
---|---|---|
committer | Fabian Groffen <grobian@gentoo.org> | 2019-05-05 22:04:40 +0200 |
commit | 73915971f03cabcbb64accab0c65a14d01904dd5 (patch) | |
tree | 9f1482b638ac65d9e8c45cad258f60b47a7d1fbc | |
parent | libq/atom: add colour to formatted atoms (diff) | |
download | portage-utils-73915971f03cabcbb64accab0c65a14d01904dd5.tar.gz portage-utils-73915971f03cabcbb64accab0c65a14d01904dd5.tar.bz2 portage-utils-73915971f03cabcbb64accab0c65a14d01904dd5.zip |
qdepends: allow custom formatting
This isn't yet fully useful, since information like SLOT, REPO, etc.
isn't available in the parsed atoms.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r-- | TODO.md | 2 | ||||
-rw-r--r-- | man/include/qdepends.desc | 4 | ||||
-rw-r--r-- | man/qdepends.1 | 12 | ||||
-rw-r--r-- | qdepends.c | 43 | ||||
-rwxr-xr-x | tests/qdepends/dotest | 2 |
5 files changed, 31 insertions, 32 deletions
@@ -10,7 +10,7 @@ - standardize/unify/clean up misc handling of colors define rules: - BOLD CATEGORY/ BLUE PKG GREEN ::REPO NORM [ MAGENTA USE NORM ] + BOLD CATEGORY/ BLUE PKG BKBLUE -VER YELLOW :SLOT GREEN ::REPO NORM [ MAGENTA USE NORM ] - remove odd rmspace for each string in libq/set.c (allows a lot less malloc/frees) diff --git a/man/include/qdepends.desc b/man/include/qdepends.desc index 070032ec..b9954c92 100644 --- a/man/include/qdepends.desc +++ b/man/include/qdepends.desc @@ -27,4 +27,6 @@ dependencies for the package are shown. When colours are enabled, the matched atom is highlighted in the list. In addition to just querying DEPEND, the default mode changed to query all DEPEND-variables, and return the unique atoms found in them. Automatic regular expression -match support was removed. +match support was removed. The \fB-N\fR option was removed, as the same +effect can be achieved via the new \fB-F\fR option or \fB-q\fR option. +The \fB-f\fR option was renamed to \fB-S\fR. diff --git a/man/qdepends.1 b/man/qdepends.1 index 1020b9a9..bee3bc1a 100644 --- a/man/qdepends.1 +++ b/man/qdepends.1 @@ -35,7 +35,9 @@ dependencies for the package are shown. When colours are enabled, the matched atom is highlighted in the list. In addition to just querying DEPEND, the default mode changed to query all DEPEND-variables, and return the unique atoms found in them. Automatic regular expression -match support was removed. +match support was removed. The \fB-N\fR option was removed, as the same +effect can be achieved via the new \fB-F\fR option or \fB-q\fR option. +The \fB-f\fR option was renamed to \fB-S\fR. .SH OPTIONS .TP \fB\-d\fR, \fB\-\-depend\fR @@ -56,10 +58,7 @@ package that references \fI<arg>\fR in DEPEND, RDEPEND, PDEPEND or BDEPEND. This can be useful to find consumers of a given package, e.g.\ to search for packages that have \fIlogwatch\fR in their DEPEND. .TP -\fB\-N\fR, \fB\-\-name\-only\fR -Only show category/package, instead of category/package-version. -.TP -\fB\-f\fR, \fB\-\-format\fR +\fB\-F\fR \fI<arg>\fR, \fB\-\-format\fR \fI<arg>\fR Pretty-print DEPEND declaration to be used in an ebuild. This option initiates a very different mode of operation. Instead of printing searching through packages, it constructs a multi-line @@ -70,6 +69,9 @@ a single dependency declaration. When used with the \fB\-q\fR option, only the pretty-printed dependency declaration is printed, e.g.\ the DEPEND= part is skipped. .TP +\fB\-S\fR, \fB\-\-pretty\fR +Pretty format specified depend strings. +.TP \fB\-\-root\fR \fI<arg>\fR Set the ROOT env var. .TP @@ -22,15 +22,15 @@ #include "xasprintf.h" #include "xregex.h" -#define QDEPENDS_FLAGS "drpbfNQu" COMMON_FLAGS +#define QDEPENDS_FLAGS "drpbQF:S" COMMON_FLAGS static struct option const qdepends_long_opts[] = { {"depend", no_argument, NULL, 'd'}, {"rdepend", no_argument, NULL, 'r'}, {"pdepend", no_argument, NULL, 'p'}, {"bdepend", no_argument, NULL, 'b'}, {"query", no_argument, NULL, 'Q'}, - {"name-only", no_argument, NULL, 'N'}, - {"format", no_argument, NULL, 'f'}, + {"format", a_argument, NULL, 'F'}, + {"pretty", no_argument, NULL, 'S'}, COMMON_LONG_OPTS }; static const char * const qdepends_opts_help[] = { @@ -39,14 +39,12 @@ static const char * const qdepends_opts_help[] = { "Show PDEPEND info", "Show BDEPEND info", "Query reverse deps", - "Only show package name", + "Print matched atom using given format string", "Pretty format specified depend strings", COMMON_OPTS_HELP }; #define qdepends_usage(ret) usage(ret, QDEPENDS_FLAGS, qdepends_long_opts, qdepends_opts_help, NULL, lookup_applet_idx("qdepends")) -static char qdep_name_only = 0; - /* structures / types / etc ... */ struct qdepends_opt_state { unsigned char qmode; @@ -55,6 +53,7 @@ struct qdepends_opt_state { set *udeps; char *depend; size_t depend_len; + const char *format; }; #define QMODE_DEPEND (1<<0) @@ -141,8 +140,7 @@ qdepends_results_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) ret = 1; - printf("%s%s/%s%s%s:", BOLD, catname, BLUE, - qdep_name_only ? datom->PN : pkgname, NORM); + printf("%s:", atom_format(state->format, datom, 0)); } xarrayfree_int(state->deps); @@ -179,11 +177,8 @@ qdepends_results_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) if (atom == NULL) { ret = 1; - if (!firstmatch) { - printf("%s%s/%s%s%s:", - BOLD, catname, BLUE, - qdep_name_only ? datom->PN : pkgname, NORM); - } + if (!firstmatch) + printf("%s:", atom_format(state->format, datom, 0)); firstmatch = true; printf("\n%s=\"\n", *dfile); @@ -209,12 +204,8 @@ qdepends_results_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) if (fatom == NULL) { ret = 1; - if (!firstmatch) { - printf("%s%s/%s%s%s:", - BOLD, catname, BLUE, - qdep_name_only ? datom->PN : pkgname, - NORM); - } + if (!firstmatch) + printf("%s:", atom_format(state->format, datom, 0)); firstmatch = true; snprintf(buf, sizeof(buf), "%s%s%s", @@ -263,10 +254,14 @@ int qdepends_main(int argc, char **argv) .qmode = 0, .depend = NULL, .depend_len = 0, + .format = "%[CATEGORY]%[PF]", }; size_t i; int ret; - bool do_format = false; + bool do_pretty = false; + + if (quiet) + state.format = "%[CATEGORY]%[PN]"; while ((ret = GETOPT_LONG(QDEPENDS, qdepends, "")) != -1) { switch (ret) { @@ -277,8 +272,8 @@ int qdepends_main(int argc, char **argv) case 'p': state.qmode |= QMODE_PDEPEND; break; case 'b': state.qmode |= QMODE_BDEPEND; break; case 'Q': state.qmode |= QMODE_REVERSE; break; - case 'N': qdep_name_only = 1; break; - case 'f': do_format = true; break; + case 'S': do_pretty = true; break; + case 'F': state.format = optarg; break; } } @@ -290,10 +285,10 @@ int qdepends_main(int argc, char **argv) QMODE_BDEPEND; } - if ((argc == optind) && !do_format) + if ((argc == optind) && !do_pretty) qdepends_usage(EXIT_FAILURE); - if (do_format) { + if (do_pretty) { while (optind < argc) { if (!qdepends_print_depend(stdout, argv[optind++])) return EXIT_FAILURE; diff --git a/tests/qdepends/dotest b/tests/qdepends/dotest index 6a8c3d6b..ebf0e810 100755 --- a/tests/qdepends/dotest +++ b/tests/qdepends/dotest @@ -44,7 +44,7 @@ test() { tend $? "${num} ${cmd[*]}" } -testf() { test "$1" "${3:-0}" -f "$2"; } +testf() { test "$1" "${3:-0}" -S "$2"; } # basic sanity checks testf 00 '|' 1 |