Annotation Type PicocliScript

  • @Documented
    public @interface PicocliScript
    Use PicocliScript2 instead.

    Annotation to give Groovy scripts convenient access to picocli functionality, superseded by PicocliScript2. Scripts may annotate the package statement, an import statement or a local variable with @PicocliScript and the script base class will be transformed to PicocliBaseScript.

    Also, any CommandLine.Command annotation on the same variable or import statement will be added to the script class. With the @Command annotation scripts can customize elements shown in the usage message like command name, description, headers, footers etc.

    Example usage:

     @Command(name = "myCommand", description = "does something special")
     import picocli.groovy.PicocliScript
     import picocli.CommandLine.Command
     import picocli.CommandLine.Option
     import groovy.transform.Field
     @Option(names = "-x", description = "number of repetitions")
     @Field int count;
     @Option(names = ["-h", "--help"], usageHelp = true, description = "print this help message and exit")
     @Field boolean helpRequested;
     //if (helpRequested) { CommandLine.usage(this, System.err); return 0; } // PicocliBaseScript takes care of this
     count.times {
         println "hi"
     assert this == theScript
     assert this.commandLine.commandName == "myCommand"

    Otherwise, this annotation works similar to the Groovy built-in BaseScript. Using this annotation will override the base script set by Groovy compiler or CompilerConfiguration of GroovyShell.

    To customize further, a base script class extending PicocliBaseScript may be specified as the value of this annotation, for example:

     import picocli.groovy.PicocliScript

    An alternative way to customize the base script is annotating a local variable with @PicocliScript. This way the variable type will be used as the base script class and the annotated variable will become a shortcut to this object. The type of the annotated variable must extend PicocliBaseScript.

     import picocli.groovy.PicocliScript
     import com.mycompany.MyScriptBaseClass
     @PicocliScript MyScriptBaseClass theScript;
    See Also:
    PicocliScriptASTTransformation, PicocliScript2
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      Class<?> value
    • Element Detail

      • value

        Class<?> value