Search code examples
command-line-argumentsraku

Is there a %*SUB-MAIN-OPTS pair for short option processing?


The multi sub MAIN() command line parsing in Perl6 is sweet!

As far as I can tell from the Command Line Interface docs there is only one option supported in the dynamic hash %*SUB-MAIN-OPTS to manipulate the option processing (that being :named-anywhere).

Perhaps I've missed the obvious, but is there an existing/supported option to take 'old fashioned' single dash options?

For example:

#Instead of this...
myprogram.raku --alpha=value1 --beta==value2 --chi

#... short options like this
myprogram.raku -a value1 -bvalue2 -c

Or is this best processed manually or with an external module?


Solution

  • You can sort of emulate this as-is, although you still have to an = ala -a=foo, and still technically have --a=foo in addition to --alpha and -a

    sub MAIN(:a(:$alpha)!) {
        say $alpha;
    }
    

    ...so you probably want to use https://github.com/Leont/getopt-long6

    use Getopt::Long;
    get-options("alpha=a" => my $alpha);