-
@Documented @Retention(SOURCE) @Target({LOCAL_VARIABLE,PACKAGE,TYPE,FIELD}) @Deprecated public @interface PicocliScript
Deprecated.UsePicocliScript2instead.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@PicocliScriptand the script base class will betransformedtoPicocliBaseScript.Also, any
CommandLine.Commandannotation on the same variable or import statement will be added to the script class. With the@Commandannotation 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 orCompilerConfigurationofGroovyShell.To customize further, a base script class extending
PicocliBaseScriptmay 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 tothisobject. The type of the annotated variable must extendPicocliBaseScript.import picocli.groovy.PicocliScript import com.mycompany.MyScriptBaseClass @PicocliScript MyScriptBaseClass theScript;
- Since:
- 2.0
- See Also:
PicocliScriptASTTransformation,PicocliScript2
-
-
Element Detail
-
value
Class<?> value
Deprecated.- Default:
- picocli.groovy.PicocliBaseScript.class
-
-