Permalink
Browse files

neither cmds->args nor argss appear to be the populated args, untamed…

… ornathoid
  • Loading branch information...
1 parent f93c4bb commit 82039cad216536ac49f9db74d98f38378d24ace4 @jettero committed Jul 19, 2014
Showing with 35 additions and 12 deletions.
  1. +23 −5 lib/Term/ReadLine/CLISH/Parser.pm
  2. +12 −7 t/15_parse_for_tab_completion.t
View
28 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,
@@ -103,8 +104,25 @@ sub parse_for_tab_completion {
@things_we_could_pick = map {$_->name} eval { @$cmds };
}
- unless( $line =~ m/\s$/ ) {
- my @tok = eval { @{ $tokout->{tokens} } };
+ 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
}
View
19 t/15_parse_for_tab_completion.t
@@ -12,24 +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 df size" => [ qw(size) ],
+ "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" );
}

0 comments on commit 82039ca

Please sign in to comment.