Class CommandProcessor.Option

  • Enclosing class:
    CommandProcessor

    public static class CommandProcessor.Option
    extends java.lang.Object
    A simple immutable object represents meta-data about a command option.
    Author:
    Pinaki Poddar
    • Constructor Summary

      Constructors 
      Constructor Description
      Option​(boolean requiresInput, java.lang.String... aliases)
      Create a option with given aliases.
      Option​(java.lang.String... aliases)
      Create a command with given aliases.
    • Constructor Detail

      • Option

        public Option​(java.lang.String... aliases)
        Create a command with given aliases. This option requires a value.
        Parameters:
        aliases - strings each must start with a dash (-).
      • Option

        public Option​(boolean requiresInput,
                      java.lang.String... aliases)
        Create a option with given aliases.
        Parameters:
        requiresInput - does it require a value?
        aliases - strings each must start with a dash (-).
    • Method Detail

      • isValidName

        public static boolean isValidName​(java.lang.String s)
        Affirms if the given string can be a valid option name. An option name always starts with dash and must be followed by at least one character.
      • getName

        public java.lang.String getName()
        Gets the first alias as the name.
      • setDefault

        public CommandProcessor.Option setDefault​(java.lang.String v)
        Sets the default value for this option.
        Parameters:
        v - a default value.
        Returns:
        this command itself.
        Throws:
        java.lang.IllegalStateException - if this option does not require a value.
      • getDescription

        public java.lang.String getDescription()
      • match

        public boolean match​(java.lang.String name)
        Affirms if the given name any of the aliases.
      • requiresInput

        public boolean requiresInput()
        Affirms if this option requires a value.
      • getDefaultValue

        public java.lang.String getDefaultValue()
        Gets the default value of this option.
        Returns:
        the default value. null if no default value has been set.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object