Interface CommandContext

    • Method Detail

      • hasFlag

        boolean hasFlag​(java.lang.String flagAlias)
        Gets if a flag with given alias was specified at least once.

        If the flag has multiple aliases, (for example, -f and --flag, passing f or flag to this method will return the same result, regardless of the alias specified by the user.

        Parameters:
        flagAlias - The flag's alias (without a prefixed dash)
        Returns:
        If the flag was specified
      • hasFlag

        boolean hasFlag​(Flag flag)
        Gets if the given flag was specified once.
        Parameters:
        flag - The Flag
        Returns:
        If the flag was specified
      • flagInvocationCount

        int flagInvocationCount​(java.lang.String flagKey)
        Returns how many times a given flag was invoked for this command.

        If the flag has multiple aliases, (for example, -f and --flag, passing f or flag to this method will return the same result, regardless of the alias specified by the user.

        Parameters:
        flagKey - The flag's alias (without a prefixed dash)
        Returns:
        The number of times the flag was specified
      • flagInvocationCount

        int flagInvocationCount​(Flag flag)
        Returns how many times a given Flag was invoked for this command.
        Parameters:
        flag - The Flag
        Returns:
        The number of times the flag was specified
      • hasAny

        boolean hasAny​(Parameter.Value<?> parameter)
        Returns whether this context has any value for the given argument key.
        Parameters:
        parameter - the Parameter associated with the argument
        Returns:
        whether there are any values present
      • hasAny

        boolean hasAny​(Parameter.Key<?> key)
        Returns whether this context has any value for the given argument key.
        Parameters:
        key - The key to look up
        Returns:
        whether there are any values present
      • one

        <T> java.util.Optional<T> one​(Parameter.Value<T> parameter)
                               throws java.lang.IllegalArgumentException
        Gets the value for the given key if the key has only one value.
        Type Parameters:
        T - the expected type of the argument
        Parameters:
        parameter - the Parameter associated with the argument
        Returns:
        the argument
        Throws:
        java.lang.IllegalArgumentException - if more than one value for the key was found
      • one

        <T> java.util.Optional<T> one​(Parameter.Key<T> key)
                               throws java.lang.IllegalArgumentException
        Gets the value for the given key if the key has only one value.
        Type Parameters:
        T - the expected type of the argument
        Parameters:
        key - the key to get
        Returns:
        the argument
        Throws:
        java.lang.IllegalArgumentException - if more than one value for the key was found
      • requireOne

        <T> T requireOne​(Parameter.Value<T> parameter)
                  throws java.util.NoSuchElementException,
                         java.lang.IllegalArgumentException
        Gets the value for the given key if the key has only one value, otherwise, throws a NoSuchElementException.
        Type Parameters:
        T - the expected type of the argument
        Parameters:
        parameter - the Parameter associated with the argument
        Returns:
        the argument
        Throws:
        java.util.NoSuchElementException - if no value for the key was found
        java.lang.IllegalArgumentException - if more than one value for the key was found
      • requireOne

        <T> T requireOne​(Parameter.Key<T> key)
                  throws java.util.NoSuchElementException,
                         java.lang.IllegalArgumentException
        Gets the value for the given key if the key has only one value, otherwise, throws a NoSuchElementException.
        Type Parameters:
        T - the expected type of the argument
        Parameters:
        key - the key to get
        Returns:
        the argument
        Throws:
        java.util.NoSuchElementException - if no value for the key was found
        java.lang.IllegalArgumentException - if more than one value for the key was found
      • all

        <T> java.util.Collection<? extends T> all​(Parameter.Value<T> parameter)
        Gets all values for the given argument. May return an empty list if no values are present.
        Type Parameters:
        T - the expected type of the argument
        Parameters:
        parameter - the Parameter associated with the argument
        Returns:
        the argument
      • all

        <T> java.util.Collection<? extends T> all​(Parameter.Key<T> key)
        Gets all values for the given argument. May return an empty list if no values are present.
        Type Parameters:
        T - the type of value to get
        Parameters:
        key - The key to get values for
        Returns:
        the collection of all values