unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/4] lei: support implicit stdin by default
Date: Sun, 30 May 2021 06:33:58 +0000	[thread overview]
Message-ID: <20210530063358.25095-5-e@80x24.org> (raw)
In-Reply-To: <20210530063358.25095-1-e@80x24.org>

This adds implicit stdin suppport for p2q and lcat,
while rm and rediff no longer need explicit support
for it.
---
 lib/PublicInbox/LEI.pm       | 12 ++++++++++--
 lib/PublicInbox/LeiRediff.pm |  1 -
 lib/PublicInbox/LeiRm.pm     |  1 -
 t/lei-p2q.t                  |  4 ++++
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index f2dfc320..3527cf09 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -638,7 +638,15 @@ sub optparse ($$$) {
 			my $ok;
 			for my $o (@or) {
 				if ($o =~ /\A--([a-z0-9\-]+)/) {
-					$ok = defined($OPT->{$1});
+					my $sw = $1;
+					# assume pipe/regular file on stdin
+					# w/o args means stdin
+					if ($sw eq 'stdin' && !@$argv &&
+							(-p $self->{0} ||
+							 -f _) && -r _) {
+						$OPT->{stdin} //= 1;
+					}
+					$ok = defined($OPT->{$sw});
 					last if $ok;
 				} elsif (defined($argv->[$i])) {
 					$ok = 1;
@@ -906,7 +914,7 @@ sub start_mua {
 	}
 	push @cmd, $mfolder unless defined($replaced);
 	if ($self->{sock}) { # lei(1) client process runs it
-		# restore terminal: echo $query | lei q -stdin --mua=...
+		# restore terminal: echo $query | lei q --stdin --mua=...
 		my $io = [];
 		$io->[0] = $self->{1} if $self->{opt}->{stdin} && -t $self->{1};
 		send_exec_cmd($self, $io, \@cmd, {});
diff --git a/lib/PublicInbox/LeiRediff.pm b/lib/PublicInbox/LeiRediff.pm
index 2e793df5..c8bd0dfb 100644
--- a/lib/PublicInbox/LeiRediff.pm
+++ b/lib/PublicInbox/LeiRediff.pm
@@ -201,7 +201,6 @@ sub input_eml_cb { # callback for all emails
 sub lei_rediff {
 	my ($lei, @inputs) = @_;
 	$lei->_lei_store(1)->write_prepare($lei);
-	$lei->{opt}->{stdin} = 1 if !@inputs;
 	$lei->{opt}->{'in-format'} //= 'eml';
 	# maybe it's a non-email (code) blob from a coderepo
 	my $git_dirs = $lei->{opt}->{'git-dir'} //= [];
diff --git a/lib/PublicInbox/LeiRm.pm b/lib/PublicInbox/LeiRm.pm
index 185b6a15..c6d28045 100644
--- a/lib/PublicInbox/LeiRm.pm
+++ b/lib/PublicInbox/LeiRm.pm
@@ -31,7 +31,6 @@ sub input_maildir_cb {
 sub lei_rm {
 	my ($lei, @inputs) = @_;
 	$lei->_lei_store(1)->write_prepare($lei);
-	$lei->{opt}->{stdin} = 1 if !@inputs;
 	$lei->{opt}->{'in-format'} //= 'eml';
 	my $self = bless { -wq_nr_workers => 1 }, __PACKAGE__;
 	$self->prepare_inputs($lei, \@inputs) or return;
diff --git a/t/lei-p2q.t b/t/lei-p2q.t
index f8b073cf..58506f94 100644
--- a/t/lei-p2q.t
+++ b/t/lei-p2q.t
@@ -14,6 +14,10 @@ test_lei(sub {
 	lei_ok([qw(p2q -w dfpost -)], undef, { %$lei_opt, 0 => $fh });
 	is($lei_out, "dfpost:6e006fd73b1d\n", '--stdin') or diag $lei_err;
 
+	sysseek($fh, 0, 0) or xbail "lseek: $!";
+	lei_ok([qw(p2q -w dfpost)], undef, { %$lei_opt, 0 => $fh });
+	is($lei_out, "dfpost:6e006fd73b1d\n", 'implicit --stdin');
+
 	lei_ok(qw(p2q --uri t/data/0001.patch -w), 'dfpost,dfn');
 	is($lei_out, "dfpost%3A6e006fd73b1d+".
 		"dfn%3Alib%2FPublicInbox%2FSearch.pm\n",

  parent reply	other threads:[~2021-05-30  6:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-30  6:33 [PATCH 0/4] lei lcat usability things Eric Wong
2021-05-30  6:33 ` [PATCH 1/4] lei lcat+inspect: start wiring up completion Eric Wong
2021-05-30  6:33 ` [PATCH 2/4] lei lcat: allow IMAP folder URLs w/o UIDVALIDITY Eric Wong
2021-05-30  6:33 ` [PATCH 3/4] lei lcat: support maildir: paths, too Eric Wong
2021-05-30  6:33 ` Eric Wong [this message]
2021-05-30 11:52 ` [PATCH 0/4] lei lcat usability things Eric Wong

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

  List information: https://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20210530063358.25095-5-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).