diff mbox series

pr: Add --nostdin, to disable TTY detection

Message ID 20221012230211.29402-1-palmer@rivosinc.com (mailing list archive)
State Superseded
Headers show
Series pr: Add --nostdin, to disable TTY detection | expand

Commit Message

Palmer Dabbelt Oct. 12, 2022, 11:02 p.m. UTC
I'm running b4 from a bash script that does all sorts of wacky stuff to
try and talk to the Yubikey, which causes "b4 pr" to think I'm trying to
pass it message IDs from standard in when I'm actually trying to do some
via positional arguments.  This adds a --nostdin command-line argument
to turn off the automatic TTY-based detection and just force positional
arguments.

Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
---
I added this to b4.5.rst, not sure if that was the right place to put
it.  I noticed some other arguments in the source that don't appear to
be documented in there.
---
 b4/command.py | 2 ++
 b4/pr.py      | 2 +-
 man/b4.5.rst  | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)

Comments

Konstantin Ryabitsev Oct. 27, 2022, 4:57 p.m. UTC | #1
On Wed, Oct 12, 2022 at 04:02:11PM -0700, Palmer Dabbelt wrote:
> I'm running b4 from a bash script that does all sorts of wacky stuff to
> try and talk to the Yubikey, which causes "b4 pr" to think I'm trying to
> pass it message IDs from standard in when I'm actually trying to do some
> via positional arguments.  This adds a --nostdin command-line argument
> to turn off the automatic TTY-based detection and just force positional
> arguments.

I didn't take this patch directly, because I wanted to implement this on the
global level instead of just for PR (since we do TTY detection in multiple
places). The end-result is very similar to what you need, you just have to put
the flag before the subcommand, e.g.:

    b4 --no-stdin pr [...]

Thank you for the suggestion.

-K
diff mbox series

Patch

diff --git a/b4/command.py b/b4/command.py
index b16043e..7fcf73f 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -194,6 +194,8 @@  def cmd():
                              'the identity must match a [sendemail "identity"] config section'))
     sp_pr.add_argument('--dry-run', dest='dryrun', action='store_true', default=False,
                        help='Force a --dry-run on git-send-email invocation (use with -s)')
+    sp_pr.add_argument('--nostdin', dest='nostdin', action='store_true', default=False,
+                       help="Disable TTY detection for stdin.")
     sp_pr.add_argument('msgid', nargs='?',
                        help='Message ID to process, or pipe a raw message')
     sp_pr.set_defaults(func=cmd_pr)
diff --git a/b4/pr.py b/b4/pr.py
index 1c00e75..6c5da58 100644
--- a/b4/pr.py
+++ b/b4/pr.py
@@ -472,7 +472,7 @@  def main(cmdargs):
     gitdir = cmdargs.gitdir
     lmsg = None
 
-    if not sys.stdin.isatty():
+    if not sys.stdin.isatty() and not cmdargs.nostdin:
         logger.debug('Getting PR message from stdin')
         msg = email.message_from_bytes(sys.stdin.buffer.read())
         cmdargs.msgid = b4.LoreMessage.get_clean_msgid(msg)
diff --git a/man/b4.5.rst b/man/b4.5.rst
index 073f32a..4dd079d 100644
--- a/man/b4.5.rst
+++ b/man/b4.5.rst
@@ -253,6 +253,7 @@  optional arguments:
   -l, --retrieve-links  Attempt to retrieve any Link: URLs (use with -e)
   -f MAILFROM, --from-addr MAILFROM
                         Use this From: in exploded messages (use with -e)
+  --nostdin             Disable TTY detection for stdin.
 
 *Example*: b4 pr 202003292120.2BDCB41@keescook