Package nz.org.riskscape.picocli
Class CommandLine.Model.Messages
java.lang.Object
nz.org.riskscape.picocli.CommandLine.Model.Messages
- Enclosing class:
- CommandLine.Model
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
ConstructorDescriptionMessages
(CommandLine.Model.CommandSpec spec, String baseName) Messages
(CommandLine.Model.CommandSpec spec, String baseName, ResourceBundle rb) -
Method Summary
Modifier and TypeMethodDescriptionReturns 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
or has anull ResourceBundle
.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.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
.Returns the base name of the ResourceBundle of this object ornull
.static String
Returns the ResourceBundle of the specified Messages object ornull
if the specified Messages object isnull
.
-
Constructor Details
-
Messages
-
Messages
-
Messages
-
-
Method Details
-
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
Returnstrue
if the specifiedMessages
isnull
or has anull ResourceBundle
. -
getString
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
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
Returns the ResourceBundle of the specified Messages object ornull
if the specified Messages object isnull
.- Since:
- 4.0
-
resourceBundle
Returns the ResourceBundle of the specified Messages object ornull
if the specified Messages object isnull
. -
resourceBundleBaseName
Returns the base name of the ResourceBundle of this object ornull
.- Since:
- 4.0
-
resourceBundle
Returns the ResourceBundle of this object ornull
. -
commandSpec
Returns the CommandSpec of this object, nevernull
.
-