Skip to content

Commit f9b7d83

Browse files
committed
Theoretically support single-value matches
1 parent 02e357f commit f9b7d83

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

bin/p6doc

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,37 @@ multi sub MAIN($docee, Bool :$f!) {
102102
}
103103
}
104104

105-
say "\nWe have multiple matches for '$method'\n";
106-
my %options;
107-
for %hits.keys -> $key {
108-
my $pref = $key.split(' ')[0];
109-
say "\t'$method' {$pref}s";
110-
111-
%options{$key}.push: %hits{$key}>>.subst(/^'Type::'/, '');
112-
say "\t\t" ~ %options{$key}.join("\n\t\t") ~ "\n";
113-
}
114-
115-
my %prefixes = do for %options.values -> @o { @o.map( *.comb[0].lc ) X=> @o };
116-
117105
my $final-docee;
118-
while prompt("Narrow your choice ({ %prefixes.keys.join(', ') }, or ! to quit): ").words -> $word {
119-
if $word ~~ '!' {
120-
exit 1;
121-
} elsif my $choice = $word ~~ rx:i/ @(%prefixes.keys) / {
122-
$final-docee = %prefixes{ $choice.lc };
123-
say "Loading $final-docee...";
124-
last;
125-
} else {
126-
say "$word is not a valid choice.\n";
127-
next;
106+
my $total-hits = [+] %hits.values.map( *.elems );
107+
if ! $total-hits {
108+
say "No matches for '$method'";
109+
exit 2;
110+
} elsif $total-hits == 1 {
111+
$final-docee = %hits.values[0];
112+
} else {
113+
say "\nWe have multiple matches for '$method'\n";
114+
my %options;
115+
for %hits.keys -> $key {
116+
my $pref = $key.split(' ')[0];
117+
say "\t'$method' {$pref}s";
118+
119+
%options{$key}.push: %hits{$key}>>.subst(/^'Type::'/, '');
120+
say "\t\t" ~ %options{$key}.join("\n\t\t") ~ "\n";
121+
}
122+
123+
my %prefixes = do for %options.values -> @o { @o.map( *.comb[0].lc ) X=> @o };
124+
125+
while prompt("Narrow your choice ({ %prefixes.keys.join(', ') }, or ! to quit): ").words -> $word {
126+
if $word ~~ '!' {
127+
exit 1;
128+
} elsif my $choice = $word ~~ rx:i/ @(%prefixes.keys) / {
129+
$final-docee = %prefixes{ $choice.lc };
130+
say "Loading $final-docee...";
131+
last;
132+
} else {
133+
say "$word is not a valid choice.\n";
134+
next;
135+
}
128136
}
129137
}
130138

0 commit comments

Comments
 (0)