Thanks for the reply!
That was the issue, the missing '=', and the order. I thought that
because it was a named parameter the order wouldn't matter.
Regarding the second question, on how to have the same switch multiple
times, using a @ sigil doesn't work:
Code:
subset Layout of Str where * ~~ /^<[12345]>\+[kk|1]$|^6\+$|^[studio|unusual]$/;
multi sub MAIN("apt",
Layout :@layout! #= Apartment layout. Values accepted:
1+kk,2+kk,...,5+kk, 6+, studio, unusual
) {
say "enter!";
}
When invoking:
$> raku bin/script.raku --layout='unusual' --layout='1+kk' apt
Usage:
bin/script.raku --layout=<Layout> ... apartment
--layout=<Layout> ... Apartment layout. Values accepted:
1+kk,2+kk,...,5+kk, 6+, studio, unusual
Unfortunately I'm unable to find any example in google on how to do
this. I guess i will have to look for some module.
Best regards,
David Santiago
Patrick Spek via perl6-users <[email protected]> escreveu no dia
segunda, 6/01/2020 à(s) 09:25:
>
> On Sun, 5 Jan 2020 22:32:02 +0000
> David Santiago <[email protected]> wrote:
>
> > Hello.
> >
> > I'm following
> > https://docs.raku.org/language/5to6-nutshell#Getopt::Long but i still
> > haven't figured it out how do i use a constraint in a named parameter
> > when processing a command line.
> >
> > I have this piece of code:
> >
> > multi sub MAIN("apt",
> > :$layout where $layout ~~
> > /^<[12345]>\+[kk|1]$|^6\+$|^[studio|unusual]$/ #= Apartment layout.
> > Values accepted: 1+kk,2+kk,...,5+kk, 6+, studio, unusual
> > ) {
> > say "Enter";
> > }
> >
> > however when i run it i get the --help message:
> >
> > $ raku script.raku apt --layout '1+kk'
> > Usage:
> > script.raku [--layout=<Any where { ... }>] apartment
> >
> > --layout=<Any where { ... }> Apartment layout. Values accepted:
> > 1+kk,2+kk,...,5+kk, 6+, studio, unusual
> >
> >
> > If i make layout a positional parameter then it works correctly. Is
> > there a way to make this work with a named parameter?
> > And how do i make possible to use the "--layout" option several times?
> > Changing the parameter from $layout to @layout doesn't work.
> >
> >
> >
> > Best regards,
> > David Santiago
>
> Hi David,
>
> The default parameter handling of Raku requires you to use an "=" sign
> between the option name and value. Additionally, the option needs to be
> before any positional arguments. Try running it as follows:
>
> raku script.raku --layout='1+kk' apt
>
> As for the ability to add it several times, I believe using an @ sigil
> instead of a $ sigil should work, but perhaps someone else has spotted
> an issue that I missed here.
>
> --
> With kind regards,
>
> Patrick Spek
>
>
> www: https://www.tyil.nl/
> mail: [email protected]
> pgp: 1660 F6A2 DFA7 5347 322A 4DC0 7A6A C285 E2D9 8827
>
> social: https://soc.fglt.nl/tyil
> git: https://gitlab.com/tyil/