- java.lang.Object
-
- io.github.mmm.cli.CliArgument
-
public abstract class CliArgument extends Object
A single argument of amainmethod from a command-line-interface (CLI). ACliArgumentis either aCliOptionor aCliValue.- See Also:
CliArgs.getFirst(),getNext()
-
-
Field Summary
Fields Modifier and Type Field Description static StringEND_OPTIONSTheargumentto indicate the end of the options.
-
Constructor Summary
Constructors Modifier Constructor Description protectedCliArgument(String arg)The constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Stringget()CliArgumentgetNext()CliOptiongetNextOption()CliValuegetNextValue()abstract StringgetOptionName()StringgetValue()List<String>getValues()LikegetValue()but returns all the next values.abstract booleanisEndOptions()abstract booleanisLongOption()abstract booleanisOption()abstract booleanisShortOption()abstract booleanisValue()StringtoString()
-
-
-
Field Detail
-
END_OPTIONS
public static final String END_OPTIONS
Theargumentto indicate the end of the options. If this string is given as argument, any further arguments are treated asvalues. This allows to provideCliValues (e.g. a filename) starting with a hyphen ('-'). Please note that the first occurrence of this string given as argument will not be supplied asCliArgumentbut only parsed internally to hide complexity for the developer using this API.- See Also:
- Constant Field Values
-
-
Method Detail
-
get
public String get()
- Returns:
- the argument text (e.g. "-h" for
CliShortOption, "--help" forCliLongOption, or "archive.zip" for aCliValue.
-
getOptionName
public abstract String getOptionName()
- Returns:
- the name of a
CliOptionornullif not anoption(in case of aCliValue). For theCliShortOption"-h" this method will return "h", and forCliLongOption"--help" it will return "help".
-
isOption
public abstract boolean isOption()
- Returns:
trueif thisCliArgumentis aCliOption(e.g. "-h" or "--help"),falseotherwise (if it is aCliValue).
-
isShortOption
public abstract boolean isShortOption()
- Returns:
trueif thisCliArgumentis aCliShortOption(e.g. "-h"),falseotherwise.
-
isLongOption
public abstract boolean isLongOption()
- Returns:
trueif thisCliArgumentis aCliLongOption(e.g. "--help"),falseotherwise.
-
isValue
public abstract boolean isValue()
- Returns:
trueif thisCliArgumentis aCliValue,falseotherwise (if it is aCliOption).
-
isEndOptions
public abstract boolean isEndOptions()
- Returns:
trueifEND_OPTIONSwas detected,falseotherwise. IfEND_OPTIONSis parsed for the first time, it will be skipped, all following arguments will be parsed asCliValueno matter if they start with hyphen ('-') or not and will returntruefor this method.
-
getNext
public CliArgument getNext()
- Returns:
- the next
CliArgumentornullif this is the last argument.
-
getNextOption
public CliOption getNextOption()
-
getNextValue
public CliValue getNextValue()
-
getValue
public String getValue()
If this is aCliOptionfollowed by aCliValue, this method will return that value (e.g. for "--key foo" it will return "foo"). If however suchCliOptionis followed by anotherCliOptionor is the lastCliArgument, this method will returnnull(e.g. for "-x -z"). Finally, if this is aCliValue, this method will return itsvalue.
-
getValues
public List<String> getValues()
LikegetValue()but returns all the next values.- Returns:
- a
Listwith thevalueof thisCliArgumentfollowed by allnextCliValues available. IfgetValue()returnnullthis method will return anemptyList.
-
-