Class RequiredArg

  • All Implemented Interfaces:
    DslArg

    public class RequiredArg
    extends SimpleDslArg
    A required argument.

    An exception will be thrown when parsing the arguments if a value is not supplied for this argument. The name of the argument may be omitted if required arguments are listed first. For example with the params:

    
     public void login(String... args) {
         DslParams params = new DslParams(args,
                                          new RequiredParam("user"),
                                          new RequiredParam("password"));
     }
     

    The following two calls are exactly equivalent:

    
     login("joan", "myPassword");
     login("user: joan", "password: myPassword");
     

    Required arguments can be supplied out of order if the name is specified, so the following is also equivalent:

    
     login("password: myPassword", "user: joan");
     

    It is highly recommended including the argument name if there is any ambiguity about the meaning of the argument.

    By default, only a single value is allowed. Multiple values can be allowed by calling setAllowMultipleValues().

    • Constructor Detail

      • RequiredArg

        public RequiredArg​(java.lang.String name)
    • Method Detail

      • setDefault

        public RequiredArg setDefault​(java.lang.String defaultValue)
        Description copied from class: SimpleDslArg
        Set a default value for this argument.

        If a default is provided, the argument will be considered to always have a value, and will return the default if no other value is provided by the caller.

        Overrides:
        setDefault in class SimpleDslArg
        Parameters:
        defaultValue - the default value for the argument.
        Returns:
        this argument
      • setAllowedValues

        public RequiredArg setAllowedValues​(java.lang.String... allowedValues)
        Description copied from class: SimpleDslArg
        Restrict the allowed values for this argument to the specified set.

        Specifying a value outside this set will result in an exception being thrown when parsing the arguments.

        Overrides:
        setAllowedValues in class SimpleDslArg
        Parameters:
        allowedValues - the allowable values for this argument.
        Returns:
        this argument
      • setAllowMultipleValues

        public RequiredArg setAllowMultipleValues()
        Description copied from class: SimpleDslArg
        Allow multiple values to be specified for this argument, either as separate arguments or using comma (,) as a delimiter.

        The following calls are equivalent:

        
         verifyUsersPresent("user: joan", "user: jenny", "user: joanne");
         verifyUsersPresent("user: joan, jenny, joanne");
         
        Overrides:
        setAllowMultipleValues in class SimpleDslArg
        Returns:
        this argument
        See Also:
        SimpleDslArg.setAllowMultipleValues(String)
      • setAllowMultipleValues

        public RequiredArg setAllowMultipleValues​(java.lang.String delimiter)
        Description copied from class: SimpleDslArg
        Allow multiple values to be specified for this argument, either as separate arguments or using the specified string as a delimiter.
        Overrides:
        setAllowMultipleValues in class SimpleDslArg
        Parameters:
        delimiter - the delimiter to use to separate values
        Returns:
        this argument
        See Also:
        SimpleDslArg.setAllowMultipleValues()