Annotation Type CommandLine.Command


  • @Retention(RUNTIME)
    @Target({TYPE,LOCAL_VARIABLE,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",
            description = "Encrypt FILE(s), or standard input, to standard output or to the output file.",
            footer      = "Copyright (c) 2017")
     public class Encrypt {
         @Parameters(paramLabel = "FILE", type = File.class, 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;
     }

    The structure of a help message looks like this:

    • [header]
    • [synopsis]: Usage: <commandName> [OPTIONS] [FILE...]
    • [description]
    • [parameter list]: [FILE...] Any number of input files
    • [option list]: -h, --help prints this help message and exits
    • [footer]
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean abbreviateSynopsis
      Specify true to generate an abbreviated synopsis like "<main> [OPTIONS] [PARAMETERS...]".
      String commandListHeading
      Set the heading preceding the subcommands list.
      String[] customSynopsis
      Specify one or more custom synopsis lines to display instead of an auto-generated synopsis.
      String[] description
      Optional text to display between the synopsis line(s) and the list of options.
      String descriptionHeading
      Set the heading preceding the description section.
      String[] footer
      Optional text to display after the list of options.
      String footerHeading
      Set the heading preceding the footer section.
      String[] header
      Optional summary description of the command, shown before the synopsis.
      String headerHeading
      Set the heading preceding the header section.
      String name
      Program name to show in the synopsis.
      String optionListHeading
      Set the heading preceding the options list.
      String parameterListHeading
      Set the heading preceding the parameters list.
      char requiredOptionMarker
      Prefix required options with this character in the options list.
      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.
      Class<?>[] subcommands
      A list of classes to instantiate and register as subcommands.
      String synopsisHeading
      Set the heading preceding the synopsis text.
      String[] version
      Version information for this command, to print to the console when the user specifies an option to request version help.