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 Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void addReceiver​(ArgumentReceiver receiver)
      Adds an argument receiver to the argument list.
      java.util.List<java.lang.String> getPositional()
      Gets the positional arguments.
      <T extends ArgumentReceiver>
      T
      getReceiver​(java.lang.Class<T> type)
      Get a receiver by class.
      java.lang.Iterable<ArgumentReceiver> getReceivers()
      Get the argument receivers registered with the Arguments list.
      boolean hasNext()
      Checks if any arguments are remaining.
      boolean hasReceiver​(java.lang.Class<? extends ArgumentReceiver> receiverClass)
      Check if this class contains a receiver.
      static Arguments of​(java.lang.String[] args)  
      java.lang.String peek()
      Peeks at the next value in the argument list without shifting it.
      java.lang.String shift()
      Shifts off the next value in the argument list or returns null.
      java.lang.String shiftFor​(java.lang.String parameter)
      Expects an argument value for a parameter by name.
    • Method Detail

      • of

        static Arguments of​(java.lang.String[] args)
      • addReceiver

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

        boolean hasReceiver​(java.lang.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​(java.lang.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:
        java.lang.NullPointerException - if not found.
      • getReceivers

        java.lang.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

        java.lang.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

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

        java.lang.String shiftFor​(java.lang.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

        java.util.List<java.lang.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 "--".