Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple MAIN signatures

Tags:

signature

raku

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.

like image 928
Antonio Gamiz Delgado Avatar asked Jul 13 '19 10:07

Antonio Gamiz Delgado


People also ask

Can we have multiple main method?

From the above program, we can say that Java can have multiple main methods but with the concept of overloading. There should be only one main method with parameter as string[ ] arg.

What is main method signature?

The signature of the main method is public static void main(String[] ags). public static void main(String a[]) is the main entry point signature for a typical Java program. So you should get on with this method signature. Java Runtime tries to find a method with name "main" with argument types "String[]". Read More.

How many main methods are there in Java?

Java's main method is composed of six terms — three reserved words, the main method name, a reference type and a variable name: public – Java's main function requires a public access modified. static – Java's main method is static, which means no instances need to be created beforehand to invoke it.

Which of the following are valid declarations of the main () function according to ISO C?

Microsoft C or, optionally, int main(int argc, char *argv[], char *envp[]); Alternatively, the main and wmain functions can be declared as returning void (no return value).


1 Answers

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

like image 127
Elizabeth Mattijsen Avatar answered Oct 21 '22 00:10

Elizabeth Mattijsen