- java.lang.Object
-
- net.sourceforge.argparse4j.internal.SubparsersImpl
-
- All Implemented Interfaces:
Subparsers
public final class SubparsersImpl extends java.lang.Object implements Subparsers
The application code must not use this class directly.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringdescription_private java.lang.Stringdest_private java.lang.Stringhelp_private ArgumentParserImplmainParser_private java.lang.Stringmetavar_private java.util.Map<java.lang.String,SubparserImpl>parsers_The key is subparser command or alias name and value is subparser object.private java.lang.Stringtitle_
-
Constructor Summary
Constructors Constructor Description SubparsersImpl(ArgumentParserImpl mainParser)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddAlias(SubparserImpl subparser, java.lang.String... alias)Adds Subparser alias names for given Subparser.SubparserImpladdParser(java.lang.String command)Adds and returnsSubparserobject with given sub-command name.SubparserImpladdParser(java.lang.String command, boolean addHelp)Adds and returnsSubparserobject with given sub-command name and addHelp.SubparserImpladdParser(java.lang.String command, boolean addHelp, java.lang.String prefixChars)Adds and returnsSubparserobject with given sub-command name, addHelp and prefixChars.SubparsersImpldescription(java.lang.String description)Sets the text to display to briefly describe sub-commands in the help message.SubparsersImpldest(java.lang.String dest)Sets the name of attribute which the selected command name is stored.(package private) java.lang.StringformatShortSyntax()(package private) java.util.Collection<java.lang.String>getCommands()Returns collection of the sub-command name under this object.java.lang.StringgetDescription()java.lang.StringgetTitle()(package private) booleanhasNotSuppressedSubCommand()Return true if SubparserImpl has at least one sub-command whose help output is not suppressed.(package private) booleanhasSubCommand()SubparsersImplhelp(java.lang.String help)Sets the text to display in the help message for sub-commands.private java.lang.Stringlocalize(java.lang.String messageKey)SubparsersImplmetavar(java.lang.String metavar)Sets the text used to represent sub-commands in help messages.(package private) voidparseArg(ParseState state, java.util.Map<java.lang.String,java.lang.Object> opts)(package private) voidprintSubparserHelp(java.io.PrintWriter writer, int format_width)Writes the help message for this and descendants.private SubparserImplresolveNextSubparser(java.lang.String command)Get next SubparserImpl from given command and state.SubparsersImpltitle(java.lang.String title)Sets the text to display as a title of sub-commands in the help message.
-
-
-
Field Detail
-
mainParser_
private final ArgumentParserImpl mainParser_
-
parsers_
private final java.util.Map<java.lang.String,SubparserImpl> 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_
private java.lang.String help_
-
title_
private java.lang.String title_
-
description_
private java.lang.String description_
-
dest_
private java.lang.String dest_
-
metavar_
private java.lang.String metavar_
-
-
Constructor Detail
-
SubparsersImpl
SubparsersImpl(ArgumentParserImpl mainParser)
-
-
Method Detail
-
addParser
public SubparserImpl addParser(java.lang.String command)
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
public SubparserImpl addParser(java.lang.String command, boolean addHelp)
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
public SubparserImpl addParser(java.lang.String command, boolean addHelp, java.lang.String prefixChars)
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
public SubparsersImpl dest(java.lang.String 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
public SubparsersImpl help(java.lang.String 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
public SubparsersImpl title(java.lang.String 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
public java.lang.String getTitle()
-
description
public SubparsersImpl description(java.lang.String 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
public java.lang.String getDescription()
-
metavar
public SubparsersImpl metavar(java.lang.String 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
private SubparserImpl resolveNextSubparser(java.lang.String command) throws ArgumentParserException
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
void parseArg(ParseState state, java.util.Map<java.lang.String,java.lang.Object> opts) throws ArgumentParserException
- Throws:
ArgumentParserException
-
formatShortSyntax
java.lang.String formatShortSyntax()
-
printSubparserHelp
void printSubparserHelp(java.io.PrintWriter writer, int format_width)Writes the help message for this and descendants.- Parameters:
writer- The writer to outputformat_width- column width
-
getCommands
java.util.Collection<java.lang.String> getCommands()
Returns collection of the sub-command name under this object.- Returns:
- collection of the sub-command name
-
addAlias
void addAlias(SubparserImpl subparser, java.lang.String... alias)
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
private java.lang.String localize(java.lang.String messageKey)
-
-