public final class Arguments
extends java.lang.Object
Values parsed for command line arguments are canonicalized to the
long-form of an argument if available. This means that an argument
with a short name of "-h" and a long name of "--help" would be made
available in an Arguments
instance as "--help" and not "-h".
Constructor and Description |
---|
Arguments(java.util.Map<java.lang.String,java.util.List<java.lang.String>> arguments,
java.util.List<java.lang.String> positionalArguments) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
boolean |
has(java.lang.String arg)
Checks if a canonicalized argument name was provided.
|
int |
hashCode() |
java.lang.String |
parameter(java.lang.String arg)
Gets an argument by name or throws if not present.
|
java.lang.String |
parameter(java.lang.String arg,
java.lang.String defaultValue)
Gets an argument by name or return a default value if not found.
|
java.util.List<java.lang.String> |
positionalArguments()
Gets the list of positional arguments that came after named arguments.
|
java.util.List<java.lang.String> |
repeatedParameter(java.lang.String arg)
Gets a repeated argument by name or throws if not present.
|
java.util.List<java.lang.String> |
repeatedParameter(java.lang.String arg,
java.util.List<java.lang.String> defaultValues)
Gets a repeated argument by name or returns a default list if not found.
|
java.lang.String |
toString() |
public Arguments(java.util.Map<java.lang.String,java.util.List<java.lang.String>> arguments, java.util.List<java.lang.String> positionalArguments)
public boolean has(java.lang.String arg)
This method should be used for checking if a option is set rather
than calling parameter(java.lang.String)
since that method throws when an
argument cannot be found.
arg
- Argument to check for (e.g., "--help").public java.lang.String parameter(java.lang.String arg)
Returns the first value if the argument is repeated.
arg
- Argument to get (e.g., "-h", "--help").CliError
- if the argument cannot be found or if the arg is a option.public java.lang.String parameter(java.lang.String arg, java.lang.String defaultValue)
arg
- Argument to get (e.g., "-h", "--help").defaultValue
- Default value to return if not found.public java.util.List<java.lang.String> repeatedParameter(java.lang.String arg)
arg
- Argument to retrieve (e.g., "--help").CliError
- if the argument cannot be found or if the arg is a option.public java.util.List<java.lang.String> repeatedParameter(java.lang.String arg, java.util.List<java.lang.String> defaultValues)
arg
- Argument to retrieve (e.g., "--help").defaultValues
- Default list of values to return if not found.public java.util.List<java.lang.String> positionalArguments()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object