Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jettero/clish
base: 32bfd06509
...
head fork: jettero/clish
compare: 82039cad21
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
2  example/cmds/ping.pm
@@ -18,7 +18,7 @@ command(
optional_argument( size => 'validate_positive_nonzero',
help => "size of the packets in bytes" ),
- optional_argument( df => undef, help => "set the don't fragment bit" ),
+ optional_argument( df => undef, is_flag=>1, help => "set the don't fragment bit" ),
required_argument(
target => ['validate_ipv4', 'validate_ipv6', 'validate_hostname'],
View
25 lib/Term/ReadLine/CLISH.pm
@@ -410,35 +410,24 @@ sub attach_sigint {
}
THE_WHIRLYGIGS: {
- my ($i, @m);
+ my @m;
my $_matches = sub {
my ($this, $attribs, $text, $state) = @_;
my $return;
- if( $state ) {
- $i ++;
+ $attribs->{completion_append_character} = $text =~ m/^(["'])/ ? "$1 " : ' ';
+ $return = $m[$state];
- } else {
- $i = 0;
- @m = map { $_->name } map {($_, @{$_->arguments})} @{ $this->parser->commands };
- $attribs->{completion_append_character} = $text =~ m/^(["'])/ ? "$1 " : ' ';
- $this->safe_talk(sub{ wtf("\$#m = ($#m); \$attribs{cac}=«$attribs->{completion_append_character}»") });
- }
-
- for(; $i < $#m ; $i++ ) {
- if( $m[$i] =~ m/^(['"]*)\Q$text/ ) {
- $return = $m[$i];
- last;
- }
- }
-
- $this->safe_talk(sub{ wtf(" \$i=$i; \$m[$i] = \$return = $return") });
+ $this->safe_talk(sub{ wtf(" \$state = $state; \$m[$state] = \$return = $return") });
return $return;
};
sub _try_to_complete {
my ($this, $term, $attribs, $text, $line, $start, $end) = @_;
+ @m = $this->parser->parse_for_tab_completion($line);
+ $this->safe_talk(sub{ wtf(" _try_to_complete \$line=\"$line\" \@m = qw(@m)") });
+
return $term->completion_matches($text, sub { $_matches->($this, $attribs, @_) });
}
}
View
2  lib/Term/ReadLine/CLISH/Command/Argument.pm
@@ -118,7 +118,7 @@ sub validate {
} else {
# If there are no validators, then we can't accept arguments for this tag
- die "incomplete argument specification (no validators)" if @$validators == 0;
+ die "$this incomplete argument specification (no validators)" if @$validators == 0;
croak "precisely what are we validating here?" unless $that;
}
View
52 lib/Term/ReadLine/CLISH/Parser.pm
@@ -36,6 +36,10 @@ has qw(output_prefix is rw isa Str default) => "% ";
__PACKAGE__->meta->make_immutable;
+
+use Data::Dump::Filtered qw(add_dump_filter); use Data::Dump qw(dump);
+add_dump_filter(sub{ my ($ctx, $obj) = @_; return { dump => "$obj»" } if $ctx->is_blessed; });
+
=head1 C<parse_for_help>
# XXX: I AM A STUB AND YOU ARE READING ME
@@ -53,9 +57,6 @@ sub parse_for_help {
return;
}
- use Data::Dump::Filtered qw(add_dump_filter); use Data::Dump qw(dump);
- add_dump_filter(sub{ my ($ctx, $obj) = @_; return { dump => "$obj»" } if $ctx->is_blessed; });
-
wtf "parse_for_help result", "\n" . dump({
line => $line,
tokout => $tokout,
@@ -84,22 +85,49 @@ sub parse_for_tab_completion {
if( $tokout->{cruft} ) {
@things_we_could_pick = (); # we'll never figure this out, it's a string or something
- } else {
+ } elsif( $line ) {
my $did_a_k = 0;
- for( 0 .. $#$cmds ) {
- # NOTE: This might be overly simplistic, or it might be right.
- # I think, mostly, you're ether going to have @$cmds==1 and have @k, *or*
- # you're going to have @$cmds != 1 and no @k
- if( my @k = keys %{$argss->[$_]} ) {
- push @things_we_could_pick, @k;
- $did_a_k = 1;
+ unless( $line =~ m/^\S+$/ ) {
+ for( 0 .. $#$cmds ) {
+ # NOTE: This might be overly simplistic, or it might be right.
+ # I think, mostly, you're ether going to have @$cmds==1 and have @k, *or*
+ # you're going to have @$cmds != 1 and no @k
+ if( my @k = keys %{$argss->[$_]} ) {
+ push @things_we_could_pick, @k;
+ $did_a_k = 1;
+ }
}
}
unless( $did_a_k ) {
- push @things_we_could_pick, map {$_->name} eval { @$cmds };
+ @things_we_could_pick = map {$_->name} eval { @$cmds };
+ }
+
+ my @tok = eval { @{ $tokout->{tokens} } };
+ warn;
+ if( $line =~ m/\s$/ ) {
+ warn;
+ if( @$cmds == 1 and @tok ) {
+ warn;
+ my $cmdaa = $cmds->[-1]->arguments;
+ warn;
+
+ if( @$cmdaa ) {
+ warn $cmdaa->[-1]->name;
+ if( $cmdaa->[-1]->name eq $tok[-1] ) {
+ warn;
+ @things_we_could_pick = () unless $cmdaa->[-1]->is_flag;
+ }
+ }
+ }
+
+ } else {
+ @things_we_could_pick = grep { m/^\Q$tok[-1]/ } @things_we_could_pick
}
+
+ } else {
+ @things_we_could_pick = $this->command_names;
}
return wantarray ? @things_we_could_pick : \@things_we_could_pick;
View
18 t/15_parse_for_tab_completion.t
@@ -12,23 +12,29 @@ my $clish = Term::ReadLine::CLISH->new->add_namespace("example::cmds") or die "
$clish -> rebuild_parser;
my $parser = $clish->parser or die "couldn't make parser";
-my %LINES = (
+my @LINES = (
q => [ "quit" ],
qu => [ "quit" ],
qui => [ "quit" ],
quit => [ "quit" ],
- "ping " => [ qw(df count size target) ],
+ "ping " => [ qw(df count size target) ],
+ "ping df size" => [ qw(size) ],
+ "ping df size " => [ ], # integer next, no completion
+ "ping count " => [ ], # integer next, no completion
);
-plan tests => 0 + keys %LINES;
+my %RESULTS = @LINES;
+ @LINES = grep {!ref} @LINES;
+
+plan tests => 0 + @LINES;
$ENV{CLISH_DEBUG} = 0; # this messages up the message capture if it's set
@output = ();
-for my $line (keys %LINES) {
+for my $line (@LINES) {
my @options = sort $parser->parse_for_tab_completion($line);
- my @expect = sort @{ $LINES{$line} };
+ my @expect = sort @{ $RESULTS{$line} };
- ok( "@options" => "@expect" );
+ ok( "$line: @options" => "$line: @expect" );
}

No commit comments for this range

Something went wrong with that request. Please try again.