On Sun, 5 Jan 2020 22:32:02 +0000 David Santiago <deman...@gmail.com> 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: p.s...@tyil.nl pgp: 1660 F6A2 DFA7 5347 322A 4DC0 7A6A C285 E2D9 8827 social: https://soc.fglt.nl/tyil git: https://gitlab.com/tyil/
pgpLtA2Fn_OvR.pgp
Description: OpenPGP digital signature