Package software.amazon.smithy.cli
Class Arguments
- java.lang.Object
-
- software.amazon.smithy.cli.Arguments
-
public final class Arguments extends java.lang.Object
Container for parsed command line arguments meant to be queried by Commands.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 Summary
Constructors Constructor Description Arguments(java.util.Map<java.lang.String,java.util.List<java.lang.String>> arguments, java.util.List<java.lang.String> positionalArguments)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
-
-
Method Detail
-
has
public boolean has(java.lang.String arg)
Checks if a canonicalized argument name was provided.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.- Parameters:
arg
- Argument to check for (e.g., "--help").- Returns:
- Returns true if the argument was set.
-
parameter
public java.lang.String parameter(java.lang.String arg)
Gets an argument by name or throws if not present.Returns the first value if the argument is repeated.
- Parameters:
arg
- Argument to get (e.g., "-h", "--help").- Returns:
- Returns the value of the matching argument.
- Throws:
CliError
- if the argument cannot be found or if the arg is a option.
-
parameter
public 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.- Parameters:
arg
- Argument to get (e.g., "-h", "--help").defaultValue
- Default value to return if not found.- Returns:
- Returns the value of the matching argument.
-
repeatedParameter
public java.util.List<java.lang.String> repeatedParameter(java.lang.String arg)
Gets a repeated argument by name or throws if not present.- Parameters:
arg
- Argument to retrieve (e.g., "--help").- Returns:
- Returns a list of values for the argument.
- Throws:
CliError
- if the argument cannot be found or if the arg is a option.
-
repeatedParameter
public 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.- Parameters:
arg
- Argument to retrieve (e.g., "--help").defaultValues
- Default list of values to return if not found.- Returns:
- Returns a list of values for the argument.
-
positionalArguments
public java.util.List<java.lang.String> positionalArguments()
Gets the list of positional arguments that came after named arguments.- Returns:
- Returns the trailing positional arguments.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-