Class Arguments

java.lang.Object
software.amazon.smithy.cli.Arguments

public final class Arguments extends 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 Details

  • Method Details

    • has

      public boolean has(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 String parameter(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 String parameter(String arg, 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 List<String> repeatedParameter(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 List<String> repeatedParameter(String arg, List<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 List<String> positionalArguments()
      Gets the list of positional arguments that came after named arguments.
      Returns:
      Returns the trailing positional arguments.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object