- java.lang.Object
-
- io.github.mmm.cli.CliArgs
-
public class CliArgs extends Object
A simple wrapper for the arguments of amain
method from a command-line-interface (CLI). Allows to easily iterate and parse these arguments.- Since:
- 1.0.0
- See Also:
CliArgs(String...)
,getFirst()
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>
getDuplicatedOptions()
CliArgument
getFirst()
CliOption
getLastOption()
CliOption
getOption(boolean unique, String... options)
CliOption
getOption(boolean unique, Collection<String> options)
CliOption
getOption(String opt)
CliOption
getOption(String... options)
String[]
getOriginalArguments()
String
getOriginalArgumentsAsString()
int
getSize()
boolean
isEmpty()
String
toString()
-
-
-
Constructor Detail
-
CliArgs
public CliArgs(String... args)
The constructor.- Parameters:
args
- the command-line arguments frommain
method.
-
-
Method Detail
-
getFirst
public CliArgument getFirst()
- Returns:
- the first
CliArgument
. - See Also:
CliArgument.getNext()
,getOption(String)
-
isEmpty
public boolean isEmpty()
- Returns:
true
if empty,false
otherwise.
-
getSize
public int getSize()
- Returns:
- the number of
CliArgument
s.
-
getOption
public CliOption getOption(String opt)
- Parameters:
opt
- theoption string
(e.g. "-h" or "--help" for help option).- Returns:
- the requested
CliOption
ornull
if no suchCliOption
exists. - See Also:
getOption(String...)
-
getOption
public CliOption getOption(String... options)
- Parameters:
options
- the array ofoption string
(e.g. "-h" or "--help" for help option).- Returns:
- the first matching
CliOption
ornull
if none of the givenoptions
exists.
-
getOption
public CliOption getOption(boolean unique, String... options)
- Parameters:
unique
- -true
if not more than one of the givenoptions
should be defined (or aCliDuplicateOptionAliasException
is thrown),false
otherwise. Set this flag totrue
when you provide multiple synonym options such as ashort
and along option
.options
- the array ofoption string
(e.g. "-h" or "--help" for help option).- Returns:
- the first matching
CliOption
ornull
if none of the givenoptions
exists. - Throws:
CliDuplicateOptionAliasException
- in caseunique
istrue
and two of the givenoptions
have been found.
-
getOption
public CliOption getOption(boolean unique, Collection<String> options)
- Parameters:
unique
- -true
if not more than one of the givenoptions
should be defined (or aCliDuplicateOptionAliasException
is thrown),false
otherwise. Set this flag totrue
when you provide multiple synonym options such as ashort
and along option
.options
- the Collection ofoption string
(e.g. "-h" or "--help" for help option).- Returns:
- the first matching
CliOption
ornull
if none of the givenoptions
exists. - Throws:
CliDuplicateOptionAliasException
- in caseunique
istrue
and two of the givenoptions
have been found.
-
getOriginalArguments
public String[] getOriginalArguments()
- Returns:
- the original arguments given at
construction
.
-
getOriginalArgumentsAsString
public String getOriginalArgumentsAsString()
- Returns:
- the original arguments as a single command-line
String
.
-
-