- java.lang.Object
-
- io.github.mmm.cli.CliArgument
-
public abstract class CliArgument extends Object
A single argument of amain
method from a command-line-interface (CLI). ACliArgument
is either aCliOption
or aCliValue
.- See Also:
CliArgs.getFirst()
,getNext()
-
-
Field Summary
Fields Modifier and Type Field Description static String
END_OPTIONS
Theargument
to indicate the end of the options.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CliArgument(String arg)
The constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
get()
CliArgument
getNext()
CliOption
getNextOption()
CliValue
getNextValue()
abstract String
getOptionName()
String
getValue()
List<String>
getValues()
LikegetValue()
but returns all the next values.abstract boolean
isEndOptions()
abstract boolean
isLongOption()
abstract boolean
isOption()
abstract boolean
isShortOption()
abstract boolean
isValue()
String
toString()
-
-
-
Field Detail
-
END_OPTIONS
public static final String END_OPTIONS
Theargument
to indicate the end of the options. If this string is given as argument, any further arguments are treated asvalues
. This allows to provideCliValue
s (e.g. a filename) starting with a hyphen ('-'). Please note that the first occurrence of this string given as argument will not be supplied asCliArgument
but 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
CliOption
ornull
if 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:
true
if thisCliArgument
is aCliOption
(e.g. "-h" or "--help"),false
otherwise (if it is aCliValue
).
-
isShortOption
public abstract boolean isShortOption()
- Returns:
true
if thisCliArgument
is aCliShortOption
(e.g. "-h"),false
otherwise.
-
isLongOption
public abstract boolean isLongOption()
- Returns:
true
if thisCliArgument
is aCliLongOption
(e.g. "--help"),false
otherwise.
-
isValue
public abstract boolean isValue()
- Returns:
true
if thisCliArgument
is aCliValue
,false
otherwise (if it is aCliOption
).
-
isEndOptions
public abstract boolean isEndOptions()
- Returns:
true
ifEND_OPTIONS
was detected,false
otherwise. IfEND_OPTIONS
is parsed for the first time, it will be skipped, all following arguments will be parsed asCliValue
no matter if they start with hyphen ('-') or not and will returntrue
for this method.
-
getNext
public CliArgument getNext()
- Returns:
- the next
CliArgument
ornull
if this is the last argument.
-
getNextOption
public CliOption getNextOption()
-
getNextValue
public CliValue getNextValue()
-
getValue
public String getValue()
If this is aCliOption
followed by aCliValue
, this method will return that value (e.g. for "--key foo" it will return "foo"). If however suchCliOption
is followed by anotherCliOption
or 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
List
with thevalue
of thisCliArgument
followed by allnext
CliValue
s available. IfgetValue()
returnnull
this method will return anempty
List
.
-
-