Changeset 69c27e6 for perl/lib


Ignore:
Timestamp:
Sep 30, 2009, 1:02:36 AM (15 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
42ad917
Parents:
a3a9eb7
git-author:
David Benjamin <davidben@mit.edu> (09/23/09 01:07:46)
git-committer:
David Benjamin <davidben@mit.edu> (09/30/09 01:02:36)
Message:
Don't suggest repeated flags in complete_flags

For most commands, it doesn't make sense to provide an option twice, so
we avoid offering it again as a completion. Note: if the user happened
to pass the flag again, we'll still attempt to complete it.

To disable, use the repeat_flags keyword option. Tests update, with
complete_zwrite testing non-repeating and complete_word testing the old
behavior.

Signed-off-by: David Benjamin <davidben@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl/Completion/Util.pm

    r94ef58c r69c27e6  
    2424    my $optsdone = 0;
    2525
     26    my %flags_seen;
     27
    2628    while($idx < $ctx->word) {
    2729        my $word = $ctx->words->[$idx];
     
    3739        } elsif ($word =~ m{^-}) {
    3840            $word = "-" . substr($word, -1);
     41            $flags_seen{$word} = 1; # record flag
    3942            $flag = $word if(exists $args->{$word});
    4043        } else {
     
    5861        return;
    5962    } else {
    60         return ($optsdone ? () : (@$no_args, keys %$args),
    61                 $default ? ($default->($ctx, $argct)) : ());
     63        my @opts = $optsdone ? () : (@$no_args, keys %$args);
     64        # filter out flags we've seen if needbe
     65        @opts = grep {!$flags_seen{$_}} @opts unless $options{repeat_flags};
     66        return (@opts, $default ? ($default->($ctx, $argct)) : ());
    6267    }
    6368}
Note: See TracChangeset for help on using the changeset viewer.