The parameters received from the command line, are always Str (or IntStr if 
they look like an integer).  To allow direct matching / handling of this, we 
would need something like an EnumStr type.  I don’t think that’s going to 
happen soon.

I also tried some pre-processing on the @*ARGS array in an INIT block, but that 
fails because the default command line processing really expects something that 
works like a Str.

So, so far I’ve only been able to come up with this workaround:

sub MAIN(:$country! where (Country.enums{$_}:exists)) {
…
}

Unfortunately it will display the feedback on a wrong parameter like:

Usage:
  script.pl --country=<Any> 

but I guess that’s the best we have for this in the short-term.

> On 18 Nov 2016, at 15:40, Itsuki Toyota (via RT) 
> <perl6-bugs-follo...@perl.org> wrote:
> 
> # New Ticket Created by  Itsuki Toyota 
> # Please include the string:  [perl #130131]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=130131 >
> 
> See the following results:
> 
> $ perl6 script.p6 --country=America
> Usage:
>   script.p6 --country=<Country> 
> 
> $ perl6 script.p6 --country=1
> Usage:
>   script.p6 --country=<Country> 
> 
> 
> script.p6:
> ----
> use v6;
> 
> enum Country<China America Brazil>;
> 
> sub MAIN(Country :$country!) {
>     say $country;
> }
> ----
> 
> $ perl6 --version
> This is Rakudo version 2016.10-295-g85c7072 built on MoarVM version 
> 2016.10-71-g9d5c874
> implementing Perl 6.c.
> 
> 
> I think that if sub MAIN cannot accept enum argument, it should display any 
> error messages and die.


Reply via email to