Package picocli

Class CommandLine.Model.Messages

  • Enclosing class:
    CommandLine.Model

    public static class CommandLine.Model.Messages
    extends Object
    Utility class for getting resource bundle strings. Enhances the standard ResourceBundle with support for String arrays and qualified keys: keys that may or may not be prefixed with the fully qualified command name.

    Example properties resource bundle:

     # Usage Help Message Sections
     # ---------------------------
     # Numbered resource keys can be used to create multi-line sections.
     usage.headerHeading = This is my app. There are other apps like it but this one is mine.%n
     usage.header   = header first line
     usage.header.0 = header second line
     usage.descriptionHeading = Description:%n
     usage.description.0 = first line
     usage.description.1 = second line
     usage.description.2 = third line
     usage.synopsisHeading = Usage:\u0020
     # Leading whitespace is removed by default. Start with \u0020 to keep the leading whitespace.
     usage.customSynopsis.0 =      Usage: ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
     usage.customSynopsis.1 = \u0020 or:  ln [OPTION]... TARGET                  (2nd form)
     usage.customSynopsis.2 = \u0020 or:  ln [OPTION]... TARGET... DIRECTORY     (3rd form)
     # Headings can contain the %n character to create multi-line values.
     usage.parameterListHeading = %nPositional parameters:%n
     usage.optionListHeading = %nOptions:%n
     usage.commandListHeading = %nCommands:%n
     usage.footerHeading = Powered by picocli%n
     usage.footer = footer
    
     # Option Descriptions
     # -------------------
     # Use numbered keys to create multi-line descriptions.
     help = Show this help message and exit.
     version = Print version information and exit.
     

    Resources for multiple commands can be specified in a single ResourceBundle. Keys and their value can be shared by multiple commands (so you don't need to repeat them for every command), but keys can be prefixed with fully qualified command name + "." to specify different values for different commands. The most specific key wins. For example:

     jfrog.rt.usage.header = Artifactory commands
     jfrog.rt.config.usage.header = Configure Artifactory details.
     jfrog.rt.upload.usage.header = Upload files.
    
     jfrog.bt.usage.header = Bintray commands
     jfrog.bt.config.usage.header = Configure Bintray details.
     jfrog.bt.upload.usage.header = Upload files.
    
     # shared between all commands
     usage.footerHeading = Environment Variables:
     usage.footer.0 = footer line 0
     usage.footer.1 = footer line 1
     
    Since:
    3.6
    See Also:
    CommandLine.Command.resourceBundle(), CommandLine.Option.descriptionKey(), CommandLine.Model.ArgSpec.description(), CommandLine.Model.ArgSpec.description(), CommandLine.Model.CommandSpec.qualifiedName(String)
    • Method Detail

      • copy

        public static CommandLine.Model.Messages copy​(CommandLine.Model.CommandSpec spec,
                                                      CommandLine.Model.Messages original)
        Returns a copy of the specified Messages object with the CommandSpec replaced by the specified one.
        Parameters:
        spec - the CommandSpec of the returned Messages
        original - the Messages object whose ResourceBundle to reference
        Returns:
        a Messages object with the specified CommandSpec and the ResourceBundle of the specified Messages object
      • empty

        public static boolean empty​(CommandLine.Model.Messages messages)
        Returns true if the specified Messages is null or has a null ResourceBundle.
      • getString

        public String getString​(String key,
                                String defaultValue)
        Returns the String value found in the resource bundle for the specified key, or the specified default value if not found.
        Parameters:
        key - unqualified resource bundle key. This method will first try to find a value by qualifying the key with the command's fully qualified name, and if not found, it will try with the unqualified key.
        defaultValue - value to return if the resource bundle is null or empty, or if no value was found by the qualified or unqualified key
        Returns:
        the String value found in the resource bundle for the specified key, or the specified default value
      • getStringArray

        public String[] getStringArray​(String key,
                                       String[] defaultValues)
        Returns the String array value found in the resource bundle for the specified key, or the specified default value if not found. Multi-line strings can be specified in the resource bundle with key.0, key.1, key.2, etc.
        Parameters:
        key - unqualified resource bundle key. This method will first try to find a value by qualifying the key with the command's fully qualified name, and if not found, it will try with the unqualified key.
        defaultValues - value to return if the resource bundle is null or empty, or if no value was found by the qualified or unqualified key
        Returns:
        the String array value found in the resource bundle for the specified key, or the specified default value
      • resourceBundleBaseName

        public static String resourceBundleBaseName​(CommandLine.Model.Messages messages)
        Returns the ResourceBundle of the specified Messages object or null if the specified Messages object is null.
        Since:
        4.0
      • resourceBundle

        public static ResourceBundle resourceBundle​(CommandLine.Model.Messages messages)
        Returns the ResourceBundle of the specified Messages object or null if the specified Messages object is null.
      • resourceBundleBaseName

        public String resourceBundleBaseName()
        Returns the base name of the ResourceBundle of this object or null.
        Since:
        4.0
      • resourceBundle

        public ResourceBundle resourceBundle()
        Returns the ResourceBundle of this object or null.