Class ArgumentImpl

  • All Implemented Interfaces:
    Argument

    public final class ArgumentImpl
    extends Object
    implements Argument
    The application code must not use this class directly.
    • Method Detail

      • textualName

        public String textualName()
        Description copied from interface: Argument

        Returns textual representation of the argument name.

        For named arguments, this method returns the first argument given in ArgumentContainer.addArgument(String...). For positional arguments, this method returns the flags joined with "/", e.g. -f/--foo.

        Specified by:
        textualName in interface Argument
        Returns:
        The textual representation of the argument name.
      • nargs

        public ArgumentImpl nargs​(int n)
        Description copied from interface: Argument

        Sets the number of command line arguments that should be consumed.

        Don't give this method '*', '+' or '?'. They are converted to int value and it is not what you expect. For these strings, use Argument.nargs(String).

        Specified by:
        nargs in interface Argument
        Parameters:
        n - A positive integer
        Returns:
        this
      • nargs

        public ArgumentImpl nargs​(String n)
        Description copied from interface: Argument

        Sets the number of command line arguments that should be consumed.

        This method takes one of following string: "*", "+" and "?". If "*" is given, All command line arguments present are gathered into a List. If "+" is given, just like "*", all command line arguments present are gathered into a List. Additionally, an error message will be generated if there wasn't at least one command line argument present. If "?" is given, one argument will be consumed from the command line if possible, and produced as a single item. If no command line argument is present, the value from Argument.setDefault(Object) will be produced. Note that for named arguments, there is an additional case - the option string is present but not followed by a command line argument. In this case the value from Argument.setConst(Object) will be produced.

        Specified by:
        nargs in interface Argument
        Parameters:
        n - "*", "+" or "?"
        Returns:
        this
      • setConst

        public ArgumentImpl setConst​(Object value)
        Description copied from interface: Argument

        Sets constant values that are not read from the command line but are required for the various actions.

        The const value defaults to null.

        Specified by:
        setConst in interface Argument
        Parameters:
        value - The const value
        Returns:
        this
      • setConst

        @SafeVarargs
        public final <E> ArgumentImpl setConst​(E... values)
        Description copied from interface: Argument

        Sets list of constant values that are not read from the command line but are required for the various actions.

        The given values will be converted to List. The const value defaults to null. If you want to set non-List item, use Argument.setConst(Object).

        Specified by:
        setConst in interface Argument
        Type Parameters:
        E - The type of the values
        Parameters:
        values - The const values
        Returns:
        this
      • setDefault

        public ArgumentImpl setDefault​(Object value)
        Description copied from interface: Argument

        Sets value which should be used if the command line argument is not present.

        The default value defaults to null.

        Specified by:
        setDefault in interface Argument
        Parameters:
        value - The default value
        Returns:
        this
      • setDefault

        @SafeVarargs
        public final <E> ArgumentImpl setDefault​(E... values)
        Description copied from interface: Argument

        Sets list of values which should be used if the command line argument is not present.

        The default value defaults to null. The given values will be converted to List. If you want to set non-List item, use Argument.setDefault(Object).

        Specified by:
        setDefault in interface Argument
        Type Parameters:
        E - The type of the values
        Parameters:
        values - The default values
        Returns:
        this
      • setDefault

        public ArgumentImpl setDefault​(FeatureControl ctrl)
        Description copied from interface: Argument

        Sets special value to control default value handling.

        Currently, only FeatureControl.SUPPRESS is available. If it is given, default value is not add as a attribute.

        Specified by:
        setDefault in interface Argument
        Parameters:
        ctrl - The special value to control default value handling.
        Returns:
        this
      • type

        public <T> ArgumentImpl type​(Class<T> type)
        Description copied from interface: Argument

        Sets the type which the command line argument should be converted to.

        By default, type is String, which means no conversion is made. The type must have a constructor which takes one String argument.

        As a convenience, if one of following primitive types (boolean.class, byte.class, short.class, int.class, long.class, float.class and double.class) is specified, it is converted to its wrapped type counterpart. For example, if int.class is given, it is silently converted to Integer.class.

        Specified by:
        type in interface Argument
        Type Parameters:
        T - The type of the value this argument accepts
        Parameters:
        type - The type which the command line argument should be converted to.
        Returns:
        this
      • type

        public <T> ArgumentImpl type​(ArgumentType<T> type)
        Description copied from interface: Argument

        Sets ArgumentType object which converts command line argument to appropriate type.

        This would be useful if you need to convert the command line argument into a type which does not have a constructor with one String argument.

        Specified by:
        type in interface Argument
        Type Parameters:
        T - The type of the value this argument accepts
        Parameters:
        type - The ArgumentType object
        Returns:
        this
      • required

        public ArgumentImpl required​(boolean required)
        Description copied from interface: Argument

        If true is given, this named argument must be specified in command line otherwise error will be issued.

        The default value is false. This object is a positional argument, this property is ignored.

        Specified by:
        required in interface Argument
        Parameters:
        required - true or false
        Returns:
        this
      • choices

        public <E> ArgumentImpl choices​(Collection<E> values)
        Description copied from interface: Argument
        Sets a collection of the allowable values for the argument.
        Specified by:
        choices in interface Argument
        Type Parameters:
        E - The type of the values
        Parameters:
        values - A collection of the allowable values
        Returns:
        this
      • choices

        @SafeVarargs
        public final <E> ArgumentImpl choices​(E... values)
        Description copied from interface: Argument
        Sets a collection of the allowable values for the argument.
        Specified by:
        choices in interface Argument
        Type Parameters:
        E - The type of the values
        Parameters:
        values - A collection of the allowable values
        Returns:
        this
      • dest

        public ArgumentImpl dest​(String dest)
        Description copied from interface: Argument

        The name of the attribute to be added.

        The default value is For positional arguments, The default value is normally supplied as the first argument to ArgumentParser.parseArgs(String[]). For named arguments, ArgumentParser generates the default value of dest by taking the first long option string and stripping away the initial -- string. If no long option strings were supplied, dest will be derived from the first short option string by stripping the initial - character. Any internal - characters will be converted to _.

        Specified by:
        dest in interface Argument
        Parameters:
        dest - The name of the attribute to be added
        Returns:
        this
      • metavar

        public ArgumentImpl metavar​(String... metavar)
        Description copied from interface: Argument
        Set the name for the argument in usage messages.
        Specified by:
        metavar in interface Argument
        Parameters:
        metavar - The name for the argument in usage messages
        Returns:
        this
      • help

        public ArgumentImpl help​(String help)
        Description copied from interface: Argument
        Sets the brief description of what the argument does.
        Specified by:
        help in interface Argument
        Parameters:
        help - The brief description of what the argument does
        Returns:
        this
      • help

        public ArgumentImpl help​(FeatureControl ctrl)
        Description copied from interface: Argument

        Sets special value to control help message handling.

        Currently, only FeatureControl.SUPPRESS is available. If it is given, the help entry for this option is not displayed in the help message.

        Specified by:
        help in interface Argument
        Parameters:
        ctrl - The special value to control help message handling.
        Returns:
        this
      • getDest

        public String getDest()
        Description copied from interface: Argument
        Returns dest value.
        Specified by:
        getDest in interface Argument
        Returns:
        The dest value
      • getConst

        public Object getConst()
        Description copied from interface: Argument
        Returns const value.
        Specified by:
        getConst in interface Argument
        Returns:
        The const value
      • getDefault

        public Object getDefault()
        Description copied from interface: Argument
        Returns default value.
        Specified by:
        getDefault in interface Argument
        Returns:
        The default value
      • getName

        public String getName()
      • isRequired

        public boolean isRequired()
      • getMetavar

        public String[] getMetavar()
      • getHelp

        public String getHelp()