Browse files

yeah, so that was easy

  • Loading branch information...
1 parent c0aea4f commit 32bfd06509cf7ba12e71b6cac435b38e1cb5f17c @jettero committed Jul 19, 2014
Showing with 19 additions and 14 deletions.
  1. +14 −10 lib/Term/ReadLine/CLISH/Parser.pm
  2. +5 −4 t/15_parse_for_tab_completion.t
View
24 lib/Term/ReadLine/CLISH/Parser.pm
@@ -78,23 +78,27 @@ sub parse_for_tab_completion {
my $this = shift;
my $line = shift;
- my @things_we_could_pick;
my ($tokout, $cmds, $argss, $statuss) = $this->parse($line, heuristic_validation=>1);
+ my @things_we_could_pick;
if( $tokout->{cruft} ) {
@things_we_could_pick = (); # we'll never figure this out, it's a string or something
} else {
- my @TOK = @{$tokout->{tokens}};
-
- if( @TOK > 1 ) {
- my @args_with_values; # XXX: apply filters here, find applicable args
- my @args_without_values;
-
- XXX "not really done even forming this idea";
+ 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;
+ }
+ }
- } else {
- @things_we_could_pick = map { $_->name } @$cmds;
+ unless( $did_a_k ) {
+ push @things_we_could_pick, map {$_->name} eval { @$cmds };
}
}
View
9 t/15_parse_for_tab_completion.t
@@ -5,8 +5,6 @@ use lib 'example';
use Term::ReadLine::CLISH;
use Net::DNS;
-$ENV{CLISH_DEBUG} = 1; # this messages up the message capture if it's set
-
my @output;
*Term::ReadLine::CLISH::Message::spew = sub { push @output, "@_" };
@@ -20,10 +18,13 @@ my %LINES = (
qui => [ "quit" ],
quit => [ "quit" ],
- "ping " => [ qw(df count size) ],
+ "ping " => [ qw(df count size target) ],
);
-plan tests => 0 + (map { @$_ } values %LINES);
+plan tests => 0 + keys %LINES;
+
+$ENV{CLISH_DEBUG} = 0; # this messages up the message capture if it's set
+@output = ();
for my $line (keys %LINES) {
my @options = sort $parser->parse_for_tab_completion($line);

0 comments on commit 32bfd06

Please sign in to comment.