- java.lang.Object
-
- io.github.mmm.cli.CliArgs
-
public class CliArgs extends Object
A simple wrapper for the arguments of amainmethod 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()CliArgumentgetFirst()CliOptiongetLastOption()CliOptiongetOption(boolean unique, String... options)CliOptiongetOption(boolean unique, Collection<String> options)CliOptiongetOption(String opt)CliOptiongetOption(String... options)String[]getOriginalArguments()StringgetOriginalArgumentsAsString()intgetSize()booleanisEmpty()StringtoString()
-
-
-
Constructor Detail
-
CliArgs
public CliArgs(String... args)
The constructor.- Parameters:
args- the command-line arguments frommainmethod.
-
-
Method Detail
-
getFirst
public CliArgument getFirst()
- Returns:
- the first
CliArgument. - See Also:
CliArgument.getNext(),getOption(String)
-
isEmpty
public boolean isEmpty()
- Returns:
trueif empty,falseotherwise.
-
getSize
public int getSize()
- Returns:
- the number of
CliArguments.
-
getOption
public CliOption getOption(String opt)
- Parameters:
opt- theoption string(e.g. "-h" or "--help" for help option).- Returns:
- the requested
CliOptionornullif no suchCliOptionexists. - 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
CliOptionornullif none of the givenoptionsexists.
-
getOption
public CliOption getOption(boolean unique, String... options)
- Parameters:
unique- -trueif not more than one of the givenoptionsshould be defined (or aCliDuplicateOptionAliasExceptionis thrown),falseotherwise. Set this flag totruewhen you provide multiple synonym options such as ashortand along option.options- the array ofoption string(e.g. "-h" or "--help" for help option).- Returns:
- the first matching
CliOptionornullif none of the givenoptionsexists. - Throws:
CliDuplicateOptionAliasException- in caseuniqueistrueand two of the givenoptionshave been found.
-
getOption
public CliOption getOption(boolean unique, Collection<String> options)
- Parameters:
unique- -trueif not more than one of the givenoptionsshould be defined (or aCliDuplicateOptionAliasExceptionis thrown),falseotherwise. Set this flag totruewhen you provide multiple synonym options such as ashortand along option.options- the Collection ofoption string(e.g. "-h" or "--help" for help option).- Returns:
- the first matching
CliOptionornullif none of the givenoptionsexists. - Throws:
CliDuplicateOptionAliasException- in caseuniqueistrueand two of the givenoptionshave 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.
-
-