Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make `-n=3` the same as `-n 3` in Perl 6?

Tags:

raku

Perl 6 has great builtin command-line parsing via MAIN. However, I faced a problem which seems to be trivial, but I cannot figure it out.

A simple MAIN:

sub MAIN(Int :n(:$num)) {
    say "You passed: " ~ $num;
}

Then I can call my script as:

$ ./test.p6 -n=1

or:

$ ./test.p6 --num=1

But can't with:

$ ./test.p6 -n 1  # or even -n1

or:

$ ./test.p6 --num 1

I went through the design document for MAIN with no luck. How can I make this work?

like image 622
cuonglm Avatar asked Jan 26 '16 04:01

cuonglm


1 Answers

Some info:

That's a reported bug. If you discover more about this that isn't mentioned in that bug report, eg find a workaround, please consider adding a comment to the report.

For your convenience, here are the other two extant bug reports I found for MAIN: Usage does not print required type for positional params in MAIN and fail to handle numbers as option name for MAIN.

Some options:

Use an options module. Maybe Getopt::Tiny will do the trick.

Help fix #124664. Perl 6 is (mostly) written in Perl 6. I think the code that munges raw main command line args and binds them to MAIN signature variables is the 20 lines or so in process-cmd-args.

like image 153
raiph Avatar answered Oct 21 '22 10:10

raiph