Skip to content

Commit

Permalink
Theoretically support single-value matches
Browse files Browse the repository at this point in the history
  • Loading branch information
ab5tract committed Jun 11, 2015
1 parent 02e357f commit f9b7d83
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions bin/p6doc
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,37 @@ multi sub MAIN($docee, Bool :$f!) {
}
}

say "\nWe have multiple matches for '$method'\n";
my %options;
for %hits.keys -> $key {
my $pref = $key.split(' ')[0];
say "\t'$method' {$pref}s";

%options{$key}.push: %hits{$key}>>.subst(/^'Type::'/, '');
say "\t\t" ~ %options{$key}.join("\n\t\t") ~ "\n";
}

my %prefixes = do for %options.values -> @o { @o.map( *.comb[0].lc ) X=> @o };

my $final-docee;
while prompt("Narrow your choice ({ %prefixes.keys.join(', ') }, or ! to quit): ").words -> $word {
if $word ~~ '!' {
exit 1;
} elsif my $choice = $word ~~ rx:i/ @(%prefixes.keys) / {
$final-docee = %prefixes{ $choice.lc };
say "Loading $final-docee...";
last;
} else {
say "$word is not a valid choice.\n";
next;
my $total-hits = [+] %hits.values.map( *.elems );
if ! $total-hits {
say "No matches for '$method'";
exit 2;
} elsif $total-hits == 1 {
$final-docee = %hits.values[0];
} else {
say "\nWe have multiple matches for '$method'\n";
my %options;
for %hits.keys -> $key {
my $pref = $key.split(' ')[0];
say "\t'$method' {$pref}s";

%options{$key}.push: %hits{$key}>>.subst(/^'Type::'/, '');
say "\t\t" ~ %options{$key}.join("\n\t\t") ~ "\n";
}

my %prefixes = do for %options.values -> @o { @o.map( *.comb[0].lc ) X=> @o };

while prompt("Narrow your choice ({ %prefixes.keys.join(', ') }, or ! to quit): ").words -> $word {
if $word ~~ '!' {
exit 1;
} elsif my $choice = $word ~~ rx:i/ @(%prefixes.keys) / {
$final-docee = %prefixes{ $choice.lc };
say "Loading $final-docee...";
last;
} else {
say "$word is not a valid choice.\n";
next;
}
}
}

Expand Down

0 comments on commit f9b7d83

Please sign in to comment.