Class Argument

  • Direct Known Subclasses:
    TypedArgument

    public class Argument
    extends Object
    Defines a command line argument. Unlike options, argument don't have names and are identified using an index. The first index is 0 (because we are in the computer world).
    Author:
    Clement Escoffier
    See Also:
    Option
    • Field Detail

      • DEFAULT_ARG_NAME

        public static final String DEFAULT_ARG_NAME
        The default argument name displayed in the usage.
        See Also:
        Constant Field Values
      • index

        protected int index
        The argument index. Must be positive or null. It is set fo -1 by default to check that the index was set.
      • argName

        protected String argName
        The argument name used in the usage.
      • description

        protected String description
        The argument description.
      • hidden

        protected boolean hidden
        Whether or not this argument is hidden. Hidden argument are not shown in the usage.
      • required

        protected boolean required
        Whether or not this argument is mandatory. Mandatory arguments throw a MissingValueException if the user command line does not provide a value.
      • defaultValue

        protected String defaultValue
        The optional default value of this argument.
      • multiValued

        protected boolean multiValued
        Whether or not this argument can receive multiple value. Only the last argument can receive multiple values.
    • Constructor Detail

      • Argument

        public Argument()
        Creates a new empty instance of Argument.
      • Argument

        public Argument​(Argument other)
        Creates a new instance of Argument by copying other.
        Parameters:
        other - the argument to copy
      • Argument

        public Argument​(JsonObject json)
        Creates a new instance of Argument from the given JSON object.
        Parameters:
        json - the json object
        See Also:
        toJson()
    • Method Detail

      • getArgName

        public String getArgName()
        Returns:
        the arg name, null if not defined.
      • setArgName

        public Argument setArgName​(String argName)
        Sets the argument name of this Argument.
        Parameters:
        argName - the argument name, must not be null
        Returns:
        the current Argument instance
      • getDescription

        public String getDescription()
        Returns:
        the description, null if not defined.
      • setDescription

        public Argument setDescription​(String description)
        Sets the description of the Argument.
        Parameters:
        description - the description
        Returns:
        the current Argument instance
      • isHidden

        public boolean isHidden()
        Returns:
        whether or not the current Argument is hidden.
      • setHidden

        public Argument setHidden​(boolean hidden)
        Sets whether or not the current Argument is hidden.
        Parameters:
        hidden - enables or disables the visibility of this Argument
        Returns:
        the current Argument instance
      • getIndex

        public int getIndex()
        Returns:
        the argument index.
      • setIndex

        public Argument setIndex​(int index)
        Sets the argument index.
        Parameters:
        index - the index, must not be negative
        Returns:
        the current Argument instance
      • isRequired

        public boolean isRequired()
        Returns:
        whether or not the current Argument is required.
      • setRequired

        public Argument setRequired​(boolean required)
        Sets whether or not the current Argument is required.
        Parameters:
        required - true to make this argument mandatory, {@link false} otherwise
        Returns:
        the current Argument instance
      • getDefaultValue

        public String getDefaultValue()
        Returns:
        the argument default value, null if not specified.
      • setDefaultValue

        public Argument setDefaultValue​(String defaultValue)
        Sets the default value of this Argument.
        Parameters:
        defaultValue - the default value
        Returns:
        the current Argument instance
      • isMultiValued

        public boolean isMultiValued()
        Returns:
        whether or not the argument can receive several values.
      • setMultiValued

        public Argument setMultiValued​(boolean multiValued)
        Sets whether or not the argument can receive several values. Only the last argument can receive several values.
        Parameters:
        multiValued - true to mark this argument as multi-valued.
        Returns:
        the current Argument instance
      • ensureValidity

        public void ensureValidity()
        Checks that the argument configuration is valid. This method is mainly made for children classes adding constraint to the configuration. The parser verifies that arguments are valid before starting the parsing.

        If the configuration is not valid, this method throws a IllegalArgumentException.