Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

raku - Multiple MAIN signatures

I have a package with multiple main and I want to define several options:

My code is something like this:

package Perl6::Documentable::CLI {
    proto MAIN(|) is export {*}
    my %*SUB-MAIN-OPTS = :named-everywhere;

    multi MAIN(
        "setup"
    ) { ... }

    multi MAIN (
        "start"                           ,
        Str  :$topdir              = "doc",
        Bool :v(:verbose($v))      = False
    ) { ... }

But when I try to actually execute it with:

perl6 -Ilib bin/documentable start -v --topdir=ss

It outputs this line:

Usage:
  bin/documentable [--topdir=<Str>] [-v|--verbose] start

I am using %*SUB-MAIN-OPTS but it looks like it does not work neither.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The simplest solution would be to export the dynamic variable %*SUB-MAIN-OPTS, but that is still Not Yet Implemented completely: the export works sorta, but winds up being an empty hash. So not very useful.

Rakudo will call a subroutine called RUN-MAIN when it decides there is a MAIN sub to be run. You can actually export a RUN-MAIN from your module, and set up the dynamic variable, and then call the original RUN-MAIN:

sub RUN-MAIN(|c) is export {
    my %*SUB-MAIN-OPTS = :named-anywhere;
    CORE::<&RUN-MAIN>(|c)
}

For more information about RUN-MAIN, see: https://docs.raku.org/language/create-cli#index-entry-RUN-MAIN


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...