- All Implemented Interfaces:
Subparsers
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate Stringprivate Stringprivate final ArgumentParserImplprivate Stringprivate final Map<String, SubparserImpl> The key is subparser command or alias name and value is subparser object.private String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddAlias(SubparserImpl subparser, String... alias) Adds Subparser alias names for given Subparser.Adds and returnsSubparserobject with given sub-command name.Adds and returnsSubparserobject with given sub-command name and addHelp.Adds and returnsSubparserobject with given sub-command name, addHelp and prefixChars.description(String description) Sets the text to display to briefly describe sub-commands in the help message.Sets the name of attribute which the selected command name is stored.(package private) String(package private) Collection<String> Returns collection of the sub-command name under this object.getTitle()(package private) booleanReturn true if SubparserImpl has at least one sub-command whose help output is not suppressed.(package private) booleanSets the text to display in the help message for sub-commands.private StringSets the text used to represent sub-commands in help messages.(package private) voidparseArg(ParseState state, Map<String, Object> opts) (package private) voidprintSubparserHelp(PrintWriter writer, int format_width) Writes the help message for this and descendants.private SubparserImplresolveNextSubparser(String command) Get next SubparserImpl from given command and state.Sets the text to display as a title of sub-commands in the help message.
-
Field Details
-
mainParser_
-
parsers_
The key is subparser command or alias name and value is subparser object. The real command and alias names share the same subparser object. To identify the aliases, check key equals toSubparserImpl.getCommand(). If they are equal, it is not alias. -
help_
-
title_
-
description_
-
dest_
-
metavar_
-
-
Constructor Details
-
SubparsersImpl
SubparsersImpl(ArgumentParserImpl mainParser)
-
-
Method Details
-
addParser
Description copied from interface:SubparsersAdds and returns
Subparserobject with given sub-command name. The given command must be unique for each Subparsers instance.The prefixChars is inherited from main ArgumentParser.
- Specified by:
addParserin interfaceSubparsers- Parameters:
command- Sub-command name- Returns:
Subparserobject.
-
addParser
Description copied from interface:SubparsersAdds and returns
Subparserobject with given sub-command name and addHelp. The given command must be unique for each Subparsers instance.For
addHelp, seeArgumentParsers.newArgumentParser(String, boolean, String). The prefixChars is inherited from main ArgumentParser.- Specified by:
addParserin interfaceSubparsers- Parameters:
command- Sub-command nameaddHelp- If true,-h/--helpare available. If false, they are not.- Returns:
Subparserobject
-
addParser
Description copied from interface:SubparsersAdds and returns
Subparserobject with given sub-command name, addHelp and prefixChars. The given command must be unique for each Subparsers instance.For
addHelp, seeArgumentParsers.newArgumentParser(String, boolean, String).- Specified by:
addParserin interfaceSubparsers- Parameters:
command- Sub-command nameaddHelp- If true,-h/--helpare available. If false, they are not.prefixChars- The set of characters that prefix named arguments.- Returns:
Subparserobject
-
dest
Description copied from interface:SubparsersSets the name of attribute which the selected command name is stored.- Specified by:
destin interfaceSubparsers- Parameters:
dest- The name of attribute the selected command name is stored.- Returns:
- this.
-
help
Description copied from interface:SubparsersSets the text to display in the help message for sub-commands.- Specified by:
helpin interfaceSubparsers- Parameters:
help- The text to display in the help message.- Returns:
- this
-
title
Description copied from interface:SubparsersSets the text to display as a title of sub-commands in the help message.
If either title or description(
Subparsers.description(String)) is specified, sub-command help will be displayed in its own group.- Specified by:
titlein interfaceSubparsers- Parameters:
title- The text to display as a title of sub-commands- Returns:
- this
-
getTitle
-
description
Description copied from interface:SubparsersSets the text to display to briefly describe sub-commands in the help message.
If either description or title(
Subparsers.title(String)) is specified, sub-command help will be displayed in its own group.- Specified by:
descriptionin interfaceSubparsers- Parameters:
description- The text to display to briefly describe sub-commands- Returns:
- this
-
getDescription
-
metavar
Description copied from interface:SubparsersSets the text used to represent sub-commands in help messages.
By default, text to represent sub-commands are concatenation of all sub-commands. This method can override this default behavior and sets arbitrary string to use. This is useful if there are many sub-commands and you don't want to show them all.
- Specified by:
metavarin interfaceSubparsers- Parameters:
metavar- The text used to represent sub-commands in help messages- Returns:
- this
-
hasSubCommand
boolean hasSubCommand() -
hasNotSuppressedSubCommand
boolean hasNotSuppressedSubCommand()Return true if SubparserImpl has at least one sub-command whose help output is not suppressed.- Returns:
- true if SubparserImpl has at least one sub-command whose help output is not suppressed.
-
resolveNextSubparser
Get next SubparserImpl from given command and state. This function resolves abbreviated command input as well. If the given command is ambiguous,ArgumentParserExceptionwill be thrown. If no matching SubparserImpl is found, this function returns null.- Returns:
- next SubparserImpl or null
- Throws:
ArgumentParserException
-
parseArg
- Throws:
ArgumentParserException
-
formatShortSyntax
String formatShortSyntax() -
printSubparserHelp
Writes the help message for this and descendants.- Parameters:
writer- The writer to outputformat_width- column width
-
getCommands
Collection<String> getCommands()Returns collection of the sub-command name under this object.- Returns:
- collection of the sub-command name
-
addAlias
Adds Subparser alias names for given Subparser. For each SubparsersImpl instance, alias names and commands must be unique. If duplication is found,IllegalArgumentExceptionis thrown.- Parameters:
subparser- Subparser to add alias namesalias- alias name
-
localize
-