From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 22FE920078 for ; Tue, 2 Feb 2021 11:47:03 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/16] lei: q: shell completion for --(include|exclude|only) Date: Tue, 2 Feb 2021 11:46:52 +0000 Message-Id: <20210202114702.29886-7-e@80x24.org> In-Reply-To: <20210202114702.29886-1-e@80x24.org> References: <20210202114702.29886-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Because .onion URLs names are long! --- lib/PublicInbox/LEI.pm | 7 +++++++ lib/PublicInbox/LeiQuery.pm | 16 ++++++++++++++++ t/lei.t | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index b0a8358a..bb7efd59 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -229,6 +229,13 @@ my %OPTDESC = ( 'q format|f=s' => [ 'OUT|maildir|mboxrd|mboxcl2|mboxcl|mboxo|html|json|jsonl|concatjson', 'specify output format, default depends on --output'], +'q exclude=s@' => [ 'URL_OR_PATHNAME', + 'exclude specified external(s) from search' ], +'q include|I=s@' => [ 'URL_OR_PATHNAME', + 'include specified external(s) in search' ], +'q only=s@' => [ 'URL_OR_PATHNAME', + 'only use specified external(s) for search' ], + 'ls-query format|f=s' => $ls_format, 'ls-external format|f=s' => $ls_format, diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm index fd8a3bca..7c1e3606 100644 --- a/lib/PublicInbox/LeiQuery.pm +++ b/lib/PublicInbox/LeiQuery.pm @@ -94,6 +94,22 @@ sub lei_q { $lxs->do_query($self); } +# shell completion helper called by lei__complete +sub _complete_q { + my ($self, @argv) = @_; + my $ext = qr/\A(?:-I|(?:--(?:include|exclude|only)))\z/; + # $argv[-1] =~ $ext and return $self->_complete_forget_external; + my @cur; + while (@argv) { + if ($argv[-1] =~ $ext) { + my @c = $self->_complete_forget_external(@cur); + return @c if @c; + } + unshift(@cur, pop @argv); + } + (); +} + # Stuff we may pass through to curl (as of 7.64.0), see curl manpage for # details, so most options which make sense for HTTP/HTTPS (including proxy # support for Tor and other methods of getting past weird networks). diff --git a/t/lei.t b/t/lei.t index a46e46f2..33f47ae4 100644 --- a/t/lei.t +++ b/t/lei.t @@ -232,6 +232,12 @@ my $test_external = sub { "partial completion for URL $u"); is($out, "https://example.com/ibx/\n", "completed partial URL $u"); + for my $qo (qw(-I --include --exclude --only)) { + ok($lei->(qw(_complete lei q), $qo, $u), + "partial completion for URL q $qo $u"); + is($out, "https://example.com/ibx/\n", + "completed partial URL $u on q $qo"); + } } $lei->('ls-external');