picocli.groovy

## Annotation Type PicocliScript

    @Documented
     @Retention(value=SOURCE)
     @Target(value={LOCAL_VARIABLE,PACKAGE,TYPE,FIELD})
    public @interface PicocliScript

Annotation to give Groovy scripts convenient access to picocli functionality. 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")
     @PicocliScript
     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:

     @PicocliScript(com.mycompany.MyScriptBaseClass)
     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;

Since:
  2.0
See Also:
  `PicocliScriptASTTransformation`

### Optional Element Summary

Optional Elements
`Class<?>` `value`

### Element Detail

#### value

    public abstract Class<?> value

Default:
  picocli.groovy.PicocliBaseScript.class