Interface Arguments


public interface Arguments
Command line arguments list to evaluate.

Arguments are parsed on demand. To finalize parsing arguments and force validation of remaining arguments, call getPositional(). Note that because arguments are parsed on demand and whole set of arguments isn't known before getPositional() is called.

  • Method Details

    • of

      static Arguments of(String[] args)
    • addReceiver

      void addReceiver(ArgumentReceiver receiver)
      Adds an argument receiver to the argument list.
      Parameters:
      receiver - Receiver to add.
    • hasReceiver

      boolean hasReceiver(Class<? extends ArgumentReceiver> receiverClass)
      Check if this class contains a receiver.
      Parameters:
      receiverClass - Class of receiver to detect.
      Returns:
      Returns true if found.
    • getReceiver

      <T extends ArgumentReceiver> T getReceiver(Class<T> type)
      Get a receiver by class.
      Type Parameters:
      T - Type of receiver to get.
      Parameters:
      type - Type of receiver to get.
      Returns:
      Returns the found receiver.
      Throws:
      NullPointerException - if not found.
    • getReceivers

      Iterable<ArgumentReceiver> getReceivers()
      Get the argument receivers registered with the Arguments list.
      Returns:
      Returns the receivers.
    • hasNext

      boolean hasNext()
      Checks if any arguments are remaining.
      Returns:
      Returns true if there are more arguments.
    • peek

      String peek()
      Peeks at the next value in the argument list without shifting it.

      Note that arguments consumed by a ArgumentReceiver are never peeked.

      Returns:
      Returns the next argument or null if no further arguments are present.
    • shift

      String shift()
      Shifts off the next value in the argument list or returns null.
      Returns:
      Returns the next value or null.
    • shiftFor

      String shiftFor(String parameter)
      Expects an argument value for a parameter by name.
      Parameters:
      parameter - Name of the parameter to get the value of.
      Returns:
      Returns the value of the parameter.
      Throws:
      CliError - if the parameter is not present.
    • getPositional

      List<String> getPositional()
      Gets the positional arguments.

      Expects that all remaining arguments are positional, and returns them.

      If an argument is "--", then it's skipped and remaining arguments are considered positional. If any argument is encountered that isn't valid for a registered Receiver, then an error is raised. Otherwise, all remaining arguments are returned in a list.

      Subscribers for different receivers are called when this method is first called.

      Returns:
      Returns remaining arguments.
      Throws:
      CliError - if the next argument starts with "--" but isn't "--".