Skip to content
Permalink
Browse files

Improve usage message for MAIN(:@foo)

Before, such a parameter would show up as "[--foo=<Positional>]", which
although technically correct, is not very useful.  Now it will appear as
"[--foo=<Any> ...]".  Sadly, specifying constraints on :@foo, like "Str :@foo"
currently does not work.
  • Loading branch information...
lizmat committed Mar 27, 2019
1 parent 0d47db8 commit d5faa02b16b6a38a4fa6731755d2f790ec21863b
Showing with 14 additions and 6 deletions.
  1. +14 −6 src/core/Main.pm6
@@ -194,14 +194,22 @@ my sub RUN-MAIN(&main, $mainline, :$in-as-argsfiles) {
}
}
else {
my @names = $param.named_names.reverse;
$argument = @names.map({($^n.chars == 1 ?? '-' !! '--') ~ $^n}).join('|');
if $param.type !=== Bool {
my @names = $param.named_names.reverse;
$argument = @names.map({
(.chars == 1 ?? '-' !! '--') ~ $_
}).join('|');

my $type := $param.type;
if $type ~~ Positional {
$argument ~= "=<{ $constraints || "Any" }> ..."

}
elsif $type !=== Bool {
$argument ~= "=<{
$constraints || $param.type.^name
$constraints || $type.^name
}>";
if Metamodel::EnumHOW.ACCEPTS($param.type.HOW) {
my $options = $param.type.^enum_values.keys.sort.Str;
if Metamodel::EnumHOW.ACCEPTS($type.HOW) {
my $options = $type.^enum_values.keys.sort.Str;
$argument ~= $options.chars > 50
?? ' (' ~ substr($options,0,50) ~ '...'
!! " ($options)"

0 comments on commit d5faa02

Please sign in to comment.
You can’t perform that action at this time.