Skip to content

Commit

Permalink
neither cmds->args nor argss appear to be the populated args, untamed…
Browse files Browse the repository at this point in the history
… ornathoid
  • Loading branch information
jettero committed Jul 19, 2014
1 parent f93c4bb commit 82039ca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
28 changes: 23 additions & 5 deletions lib/Term/ReadLine/CLISH/Parser.pm
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
19 changes: 12 additions & 7 deletions t/15_parse_for_tab_completion.t
Expand Up @@ -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.