]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: fix completion of --no-kw / --no-keywords
authorEric Wong <e@80x24.org>
Sat, 6 Feb 2021 12:18:30 +0000 (12:18 +0000)
committerEric Wong <e@80x24.org>
Sun, 7 Feb 2021 03:34:32 +0000 (03:34 +0000)
We did not complete --no-* flags properly when multiple options
are allowed.

lib/PublicInbox/LEI.pm
t/lei.t

index b058b533c97298c144bd68b9a97c13a519da4ac7..8d5a921e1e0e1ee5df20d9f687130c180dac6571 100644 (file)
@@ -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 41d854e859a7ff3accfdfe06a61b61244ede0327..df33395712925dc3635b5dfdc7c42acaf89d3f6c 100644 (file)
--- 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 {