- java.lang.Object
-
- picocli.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
-
-
Constructor Summary
Constructors Constructor Description Messages(CommandLine.Model.CommandSpec spec, String baseName)
Messages(CommandLine.Model.CommandSpec spec, String baseName, ResourceBundle rb)
Messages(CommandLine.Model.CommandSpec spec, ResourceBundle rb)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandLine.Model.CommandSpec
commandSpec()
Returns the CommandSpec of this object, nevernull
.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.static boolean
empty(CommandLine.Model.Messages messages)
Returnstrue
if the specifiedMessages
isnull
, has anull ResourceBundle
, or has anull parent Messages
.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.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.CommandLine.Model.Messages
parent()
ResourceBundle
resourceBundle()
Returns the ResourceBundle of this object ornull
.static ResourceBundle
resourceBundle(CommandLine.Model.Messages messages)
Returns the ResourceBundle of the specified Messages object ornull
if the specified Messages object isnull
.String
resourceBundleBaseName()
Returns the base name of the ResourceBundle of this object ornull
.static String
resourceBundleBaseName(CommandLine.Model.Messages messages)
Returns the ResourceBundle of the specified Messages object ornull
if the specified Messages object isnull
.static void
setLoadBundles(boolean loadBundles)
During annotation processing, resource bundles may not be available on the classpath and thereby cause failures.
-
-
-
Constructor Detail
-
Messages
public Messages(CommandLine.Model.CommandSpec spec, String baseName)
-
Messages
public Messages(CommandLine.Model.CommandSpec spec, ResourceBundle rb)
-
Messages
public Messages(CommandLine.Model.CommandSpec spec, String baseName, ResourceBundle rb)
-
-
Method Detail
-
parent
public CommandLine.Model.Messages parent()
-
setLoadBundles
public static final void setLoadBundles(boolean loadBundles)
During annotation processing, resource bundles may not be available on the classpath and thereby cause failures. This method allows for disabling loading of resource bundles during annotation processing, preventing such errors.- Parameters:
loadBundles
- true if bundles should be loaded (default), false if bundles should not be loaded- Since:
- 4.7.6
-
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 Messagesoriginal
- 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)
Returnstrue
if the specifiedMessages
isnull
, has anull ResourceBundle
, or has anull parent Messages
.
-
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 withkey.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 ornull
if the specified Messages object isnull
.- Since:
- 4.0
-
resourceBundle
public static ResourceBundle resourceBundle(CommandLine.Model.Messages messages)
Returns the ResourceBundle of the specified Messages object ornull
if the specified Messages object isnull
.
-
resourceBundleBaseName
public String resourceBundleBaseName()
Returns the base name of the ResourceBundle of this object ornull
.- Since:
- 4.0
-
resourceBundle
public ResourceBundle resourceBundle()
Returns the ResourceBundle of this object ornull
.
-
commandSpec
public CommandLine.Model.CommandSpec commandSpec()
Returns the CommandSpec of this object, nevernull
.
-
-