java.lang.Object
io.github.mmm.cli.CliArgument
A single argument of a
main method from a command-line-interface (CLI). A CliArgument is either a
CliOption or a CliValue.- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
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:
-
-
Constructor Details
-
CliArgument
The constructor.- Parameters:
arg- theargument.
-
-
Method Details
-
get
- Returns:
- the argument text (e.g. "-h" for
CliShortOption, "--help" forCliLongOption, or "archive.zip" for aCliValue.
-
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
- Returns:
- the next
CliArgumentornullif this is the last argument.
-
getNextOption
-
getNextValue
-
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
LikegetValue()but returns all the next values.- Returns:
- a
Listwith thevalueof thisCliArgumentfollowed by allnextCliValues available. IfgetValue()returnnullthis method will return anemptyList.
-
toString
-