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=-3.8 required=3.0 tests=ALL_TRUSTED,AWL,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 DDC501F8C7 for ; Sat, 6 Feb 2021 12:18:44 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/17] lei: fix completion of --no-kw / --no-keywords Date: Sat, 6 Feb 2021 12:18:30 +0000 Message-Id: <20210206121844.10979-4-e@80x24.org> In-Reply-To: <20210206121844.10979-1-e@80x24.org> References: <20210206121844.10979-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We did not complete --no-* flags properly when multiple options are allowed. --- lib/PublicInbox/LEI.pm | 9 ++++++--- t/lei.t | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index b058b533..8d5a921e 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -274,6 +274,8 @@ my %OPTDESC = ( 'by-mid|mid:s' => [ 'MID', 'match only by Message-ID, ignoring contents' ], 'jobs:i' => 'set parallelism level', +'kw|keywords|flags!' => 'disable/enable importing flags', + # xargs, env, use "-0", git(1) uses "-z". We support z|0 everywhere 'z|0' => 'use NUL \\0 instead of newline (CR) to delimit lines', @@ -425,7 +427,7 @@ sub _help ($;$) { my (@vals, @s, @l); my $x = $sw; if ($x =~ s/!\z//) { # solve! => --no-solve - $x = "no-$x"; + $x =~ s/(\A|\|)/$1no-/g } elsif ($x =~ s/:.+//) { # optional args: $x = "mid:s" @vals = (' [', undef, ']'); } elsif ($x =~ s/=.+//) { # required arg: $x = "type=s" @@ -710,8 +712,9 @@ sub lei__complete { } puts $self, grep(/$re/, map { # generate short/long names if (s/[:=].+\z//) { # req/optional args, e.g output|o=i - } else { # negation: solve! => no-solve|solve - s/\A(.+)!\z/no-$1|$1/; + } elsif (s/!\z//) { + # negation: solve! => no-solve|solve + s/([\w\-]+)/$1|no-$1/g } map { my $x = length > 1 ? "--$_" : "-$_"; diff --git a/t/lei.t b/t/lei.t index 41d854e8..df333957 100644 --- a/t/lei.t +++ b/t/lei.t @@ -363,7 +363,7 @@ my $test_completion = sub { --mua --mua-cmd --no-local --local --verbose -v --save-as --no-remote --remote --torsocks --reverse -r )) { - ok($out{$sw}, "$sw offered as completion"); + ok($out{$sw}, "$sw offered as `lei q' completion"); } ok($lei->(qw(_complete lei q --form)), 'complete q --format'); @@ -376,6 +376,12 @@ my $test_completion = sub { ok($out{$f}, "got $sw $f as output format"); } } + ok($lei->(qw(_complete lei import)), 'complete import'); + %out = map { $_ => 1 } split(/\s+/s, $out); + for my $sw (qw(--flags --no-flags --no-kw --kw --no-keywords + --keywords)) { + ok($out{$sw}, "$sw offered as `lei import' completion"); + } }; my $test_fail = sub {