public class DefaultCommandLine extends Object implements CommandLine
CommandLine.
This implementation is not thread-safe.| Modifier and Type | Field and Description |
|---|---|
protected List<String> |
allArgs |
protected Map<Argument,List<String>> |
argumentValues |
protected CLI |
cli |
protected List<Option> |
optionsSeenInCommandLine |
protected Map<Option,List<String>> |
optionValues |
protected boolean |
valid |
| Constructor and Description |
|---|
DefaultCommandLine(CLI cli) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptMoreValues(Option option)
Checks whether or not the given option accept more values.
|
CommandLine |
addArgumentValue(String argument)
Adds an argument value.
|
DefaultCommandLine |
addRawValue(Option option,
String value) |
List<String> |
allArguments() |
CLI |
cli() |
static <T> T |
create(String value,
TypedArgument<T> argument)
Creates the value for the given argument from the given raw value.
|
static <T> T |
create(String value,
TypedOption<T> option)
Creates the value for the given option from the given raw value.
|
static <T> List<T> |
createFromList(String raw,
TypedOption<T> option) |
<T> T |
getArgumentValue(int index)
Gets the value of an argument with the given index.
|
<T> T |
getArgumentValue(String name)
Gets the value of an argument with the matching name (arg name).
|
<T> List<T> |
getArgumentValues(int index)
Gets the values of an argument with the matching index.
|
<T> T |
getOptionValue(String name)
Gets the value of an option with the matching name (can be the long name, short name or arg name).
|
<T> List<T> |
getOptionValues(String name)
Gets the values of an option with the matching name (can be the long name, short name or arg name).
|
String |
getRawValueForArgument(Argument arg)
Gets the raw value of the given argument.
|
String |
getRawValueForOption(Option option)
Gets the raw value of the given option.
|
List<String> |
getRawValuesForArgument(Argument argument)
Gets the raw values of the given argument.
|
List<String> |
getRawValuesForOption(Option option)
Gets the raw values of the given option.
|
boolean |
isArgumentAssigned(Argument arg)
Checks whether or not the given argument has been assigned in the command line.
|
boolean |
isAskingForHelp()
Checks whether or not the user has passed a "help" option and is asking for help.
|
boolean |
isFlagEnabled(String name)
Gets the value of an option marked as a flag.
|
boolean |
isOptionAssigned(Option option)
Checks whether or not the given option has been assigned in the command line.
|
boolean |
isSeenInCommandLine(Option option)
Checks whether or not the given option has been seen in the user command line.
|
boolean |
isValid()
Checks whether or not the command line is valid, i.e.
|
DefaultCommandLine |
setRawValue(Argument arg,
String rawValue) |
DefaultCommandLine |
setSeenInCommandLine(Option option)
Marks the option as seen.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreate, getRawValuesprotected final CLI cli
protected boolean valid
public DefaultCommandLine(CLI cli)
public CLI cli()
cli in interface CommandLinepublic List<String> allArguments()
allArguments in interface CommandLinepublic CommandLine addArgumentValue(String argument)
argument - the argumentDefaultCommandLine.public <T> T getOptionValue(String name)
CommandLinegetOptionValue in interface CommandLineT - the expected typename - the namenull if not setpublic boolean isFlagEnabled(String name)
CommandLineIllegalStateException.isFlagEnabled in interface CommandLinename - the option nametrue if the flag has been set in the command line, false otherwise.public <T> List<T> getOptionValues(String name)
CommandLinegetOptionValues in interface CommandLineT - the expected component typename - the namenull if not setCommandLine.getRawValuesForOption(Option)public <T> List<T> getArgumentValues(int index)
getArgumentValues in interface CommandLineT - the expected component typeindex - the indexnull if not setgetArgumentValue(int),
getRawValueForArgument(Argument)public <T> T getArgumentValue(String name)
CommandLinegetArgumentValue in interface CommandLineT - the expected typename - the namenull if not setpublic <T> T getArgumentValue(int index)
CommandLinegetArgumentValue in interface CommandLineT - the expected typeindex - the indexnull if not setpublic boolean isOptionAssigned(Option option)
CommandLineisOptionAssigned in interface CommandLineoption - the optiontrue if the option has received a value, false otherwise.public List<String> getRawValuesForOption(Option option)
CommandLinegetRawValuesForOption in interface CommandLineoption - the optionpublic List<String> getRawValuesForArgument(Argument argument)
CommandLinegetRawValuesForArgument in interface CommandLineargument - the argumentpublic DefaultCommandLine addRawValue(Option option, String value)
public String getRawValueForOption(Option option)
CommandLinegetRawValueForOption in interface CommandLineoption - the optionnull if none.public boolean acceptMoreValues(Option option)
CommandLineacceptMoreValues in interface CommandLineoption - the optiontrue if the option accepts more values, false otherwise.public String getRawValueForArgument(Argument arg)
CommandLinegetRawValueForArgument in interface CommandLinearg - the argumentnull if none.public DefaultCommandLine setRawValue(Argument arg, String rawValue)
public boolean isArgumentAssigned(Argument arg)
CommandLineisArgumentAssigned in interface CommandLinearg - the argumenttrue if the argument has received a value, false otherwise.public DefaultCommandLine setSeenInCommandLine(Option option)
option - the optionDefaultCommandLine.public boolean isSeenInCommandLine(Option option)
CommandLineisSeenInCommandLine in interface CommandLineoption - the optiontrue if the user command line has used the optionpublic static <T> T create(String value, TypedArgument<T> argument)
value - the valuepublic static <T> T create(String value, TypedOption<T> option)
value - the valuepublic static <T> List<T> createFromList(String raw, TypedOption<T> option)
public boolean isValid()
isValid in interface CommandLinetrue if the current CommandLine object is valid. false otherwise.public boolean isAskingForHelp()
isAskingForHelp in interface CommandLinetrue if the user command line has enabled a "Help" option, false otherwise.Copyright © 2020. All rights reserved.