From dd1c805949b5996a79adeb690cc0d468e2d88836 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Fri, 22 Mar 2019 17:43:44 +0100 Subject: [PATCH] Simplify candidate selection in MAIN usage A recent change tried to be smarter on which MAIN candidates to show. This was however too smart for its own good, omitting candidates when it shouldn't. Now limiting of candidates will only happen if the first given parameter matches a **constant** value as the first parameter. So if you have multiple MAIN candidates that have "foo" as the first parameter, and you give "foo" as the first command line argument, then only those candidates will be selected for the usage message if no appropriate candidate was found for execution. In all other cases, all candidates will be shown if no candidate was found for execution. Spotted at Andrew Shitov's talk at the German Perl Workshop. --- src/core/Main.pm6 | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/core/Main.pm6 b/src/core/Main.pm6 index bd0e0fef97d..3bf55a00106 100644 --- a/src/core/Main.pm6 +++ b/src/core/Main.pm6 @@ -127,25 +127,18 @@ my sub RUN-MAIN(&main, $mainline, :$in-as-argsfiles) { # Select candidates for which to create USAGE string sub usage-candidates($capture) { - my @candidates = &main.candidates; - my @positionals = $capture.list; - - my @candos; - while @positionals && !@candos { - - # Find candidates on which all these positionals match - @candos = @candidates.grep: -> $sub { - my @params = $sub.signature.params; - if @positionals <= @params { - (^@positionals).first( -> int $i { - !(@params[$i].constraints.ACCEPTS(@positionals[$i])) - } ).defined.not + my @candidates = &main.candidates.grep: { !.?is-hidden-from-USAGE } + if $capture.list -> @positionals { + my $first := @positionals[0]; + if @candidates.grep: -> $sub { + if $sub.signature.params[0].cool_constant -> $literal { + $literal.ACCEPTS($first) } + } -> @candos { + return @candos; } - @positionals.pop; } - (@candos || @candidates) - .grep: { nqp::not_i(nqp::can($_,'is-hidden-from-USAGE')) } + @candidates } for usage-candidates(capture) -> $sub {