@Retention(value=RUNTIME)
@Target(value={TYPE,LOCAL_VARIABLE,FIELD,PACKAGE})
public static @interface CommandLine.Command
Annotate your class with @Command when you want more control over the format of the generated help
message.
@Command(name = "Encrypt", mixinStandardHelpOptions = true,
description = "Encrypt FILE(s), or standard input, to standard output or to the output file.",
version = "Encrypt version 1.0",
footer = "Copyright (c) 2017")
public class Encrypt {
@Parameters(paramLabel = "FILE", description = "Any number of input files")
private List<File> files = new ArrayList<File>();
@Option(names = { "-o", "--out" }, description = "Output file (default: print to console)")
private File outputFile;
@Option(names = { "-v", "--verbose"}, description = "Verbose mode. Helpful for troubleshooting. Multiple -v options increase the verbosity.")
private boolean[] verbose;
}
The structure of a help message looks like this:
Usage: <commandName> [OPTIONS] [FILE...][FILE...] Any number of input files-h, --help prints this help message and exits| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
abbreviateSynopsis
Specify
true to generate an abbreviated synopsis like "<main> [OPTIONS] [PARAMETERS...]". |
java.lang.String[] |
aliases
Alternative command names by which this subcommand is recognized on the command line.
|
java.lang.String |
commandListHeading
Set the heading preceding the subcommands list.
|
java.lang.String[] |
customSynopsis
Specify one or more custom synopsis lines to display instead of an auto-generated synopsis.
|
java.lang.String[] |
description
Optional text to display between the synopsis line(s) and the list of options.
|
java.lang.String |
descriptionHeading
Set the heading preceding the description section.
|
java.lang.String[] |
footer
Optional text to display after the list of options.
|
java.lang.String |
footerHeading
Set the heading preceding the footer section.
|
java.lang.String[] |
header
Optional summary description of the command, shown before the synopsis.
|
java.lang.String |
headerHeading
Set the heading preceding the header section.
|
boolean |
helpCommand
Set this attribute to
true if this subcommand is a help command, and required options and positional
parameters of the parent command should not be validated. |
boolean |
hidden
Set
hidden=true if this command should not be included in the list of commands in the usage help of the parent command. |
boolean |
mixinStandardHelpOptions
Adds the standard
-h and --help usageHelp options and -V
and --version versionHelp options to the options of this command. |
java.lang.String |
name
Program name to show in the synopsis.
|
java.lang.String |
optionListHeading
Set the heading preceding the options list.
|
java.lang.String |
parameterListHeading
Set the heading preceding the parameters list.
|
char |
requiredOptionMarker
Prefix required options with this character in the options list.
|
java.lang.String |
separator
String that separates options from option parameters.
|
boolean |
showDefaultValues
Specify
true to show default values in the description column of the options list (except for
boolean options). |
boolean |
sortOptions
Specify
false to show Options in declaration order. |
java.lang.Class<?>[] |
subcommands
A list of classes to instantiate and register as subcommands.
|
java.lang.String |
synopsisHeading
Set the heading preceding the synopsis text.
|
java.lang.String[] |
version
Version information for this command, to print to the console when the user specifies an
option to request version help.
|
java.lang.Class<? extends CommandLine.IVersionProvider> |
versionProvider
Class that can provide version information dynamically at runtime.
|
public abstract java.lang.String name
"<main class>" is used.
For declaratively added subcommands, this attribute is also used
by the parser to recognize subcommands in the command line arguments.CommandLine.Model.CommandSpec.name(),
CommandLine.Help.commandName()public abstract java.lang.String[] aliases
public abstract java.lang.Class<?>[] subcommands
CommandLine.addSubcommand(String, Object) method. For example, this:
@Command(subcommands = {
GitStatus.class,
GitCommit.class,
GitBranch.class })
public class Git { ... }
CommandLine commandLine = new CommandLine(new Git());
is equivalent to this:
// alternative: programmatically add subcommands.
// NOTE: in this case there should be no `subcommands` attribute on the @Command annotation.
@Command public class Git { ... }
CommandLine commandLine = new CommandLine(new Git())
.addSubcommand("status", new GitStatus())
.addSubcommand("commit", new GitCommit())
.addSubcommand("branch", new GitBranch());
CommandLine.addSubcommand(String, Object),
CommandLine.HelpCommandpublic abstract java.lang.String separator
"=". Spaces are also accepted.CommandLine.setSeparator(String)public abstract java.lang.String[] version
CommandLine.printVersionHelp(PrintStream)public abstract java.lang.Class<? extends CommandLine.IVersionProvider> versionProvider
public abstract boolean mixinStandardHelpOptions
-h and --help usageHelp options and -V
and --version versionHelp options to the options of this command.
Note that if no version() or versionProvider() is specified, the --version option will not print anything.
public abstract boolean helpCommand
true if this subcommand is a help command, and required options and positional
parameters of the parent command should not be validated. If a subcommand marked as helpCommand is
specified on the command line, picocli will not validate the parent arguments (so no "missing required
option" errors) and the CommandLine.printHelpIfRequested(List, PrintStream, PrintStream, Help.Ansi) method will return true.true if this subcommand is a help command and picocli should not check for missing required
options and positional parameters on the parent commandpublic abstract java.lang.String headerHeading
CommandLine.Model.UsageMessageSpec.headerHeading(),
CommandLine.Help.headerHeading(Object...)public abstract java.lang.String[] header
CommandLine.Model.UsageMessageSpec.header(),
CommandLine.Help.header(Object...)public abstract java.lang.String synopsisHeading
"Usage: " (without a line
break between the heading and the synopsis text).CommandLine.Help.synopsisHeading(Object...)public abstract boolean abbreviateSynopsis
true to generate an abbreviated synopsis like "<main> [OPTIONS] [PARAMETERS...]".
By default, a detailed synopsis with individual option names and parameters is generated.CommandLine.Help.abbreviatedSynopsis(),
CommandLine.Help.detailedSynopsis(Comparator, boolean)public abstract java.lang.String[] customSynopsis
CommandLine.Help.customSynopsis(Object...)public abstract java.lang.String descriptionHeading
CommandLine.Help.descriptionHeading(Object...)public abstract java.lang.String[] description
CommandLine.Help.description(Object...)public abstract java.lang.String parameterListHeading
CommandLine.Help.parameterListHeading(Object...)public abstract java.lang.String optionListHeading
CommandLine.Help.optionListHeading(Object...)public abstract boolean sortOptions
false to show Options in declaration order. The default is to sort alphabetically.public abstract char requiredOptionMarker
public abstract boolean showDefaultValues
true to show default values in the description column of the options list (except for
boolean options). False by default.
Note that picocli 3.2 allows embedding default values anywhere in the option or positional parameter description that ignores this setting.
public abstract java.lang.String commandListHeading
"Commands:%n" (with a line break at the end).CommandLine.Help.commandListHeading(Object...)public abstract java.lang.String footerHeading
CommandLine.Help.footerHeading(Object...)public abstract java.lang.String[] footer
CommandLine.Help.footer(Object...)