commit:     6a98a8395bf825870fcb0514c61e8b26b97d2fe1
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Wed Jan 15 20:01:56 2025 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Wed Jan 15 20:01:56 2025 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=6a98a839

pquery: support input from stdin when "-" is passed as an argument

Resolves: https://github.com/pkgcore/pkgcore/issues/226
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcore/scripts/pquery.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/pkgcore/scripts/pquery.py b/src/pkgcore/scripts/pquery.py
index 7211441f..6ab6a79f 100644
--- a/src/pkgcore/scripts/pquery.py
+++ b/src/pkgcore/scripts/pquery.py
@@ -15,8 +15,9 @@ running them on source repos makes no sense.
 
 import errno
 import os
-from functools import partial
+import sys
 import typing
+from functools import partial
 
 from snakeoil.cli import arghparse
 from snakeoil.formatters import decorate_forced_wrapping
@@ -705,9 +706,17 @@ def bind_add_query(*args, **kwds):
     type=None,
     help="extended atom matching of pkgs",
 )
-def matches_finalize(targets, namespace):
+def matches_finalize(targets: list[str], namespace):
     repos = multiplex.tree(*namespace.repos)
 
+    if "-" in targets:
+        if not sys.stdin.isatty():
+            idx = targets.index("-")
+            in_targets = [x.strip() for x in sys.stdin.readlines()]
+            targets = targets[:idx] + in_targets + targets[idx + 1 :]
+        else:
+            argparser.error("reading from stdin is only valid when piping data 
in")
+
     # If current working dir is in a repo, build a path restriction; otherwise
     # match everything.
     if not targets:

Reply via email to