diff options
author | Eric Wong <e@80x24.org> | 2021-05-30 06:33:58 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-05-30 08:09:10 +0000 |
commit | 66b5829892cf0fcd5249e26be21d8b3f3ee35816 (patch) | |
tree | 5718b4ccf58aaa72a7f3fc0cc6fb4c9e4cf20c17 /lib | |
parent | f91eec7587fb88e058b12896377f4d289087d0f7 (diff) | |
download | public-inbox-66b5829892cf0fcd5249e26be21d8b3f3ee35816.tar.gz |
This adds implicit stdin suppport for p2q and lcat, while rm and rediff no longer need explicit support for it.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/LEI.pm | 12 | ||||
-rw-r--r-- | lib/PublicInbox/LeiRediff.pm | 1 | ||||
-rw-r--r-- | lib/PublicInbox/LeiRm.pm | 1 |
3 files changed, 10 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; |