Class RequiredArg
- java.lang.Object
-
- com.lmax.simpledsl.api.SimpleDslArg
-
- com.lmax.simpledsl.api.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 Summary
Constructors Constructor Description RequiredArg(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RequiredArgsetAllowedValues(java.lang.String... allowedValues)Restrict the allowed values for this argument to the specified set.RequiredArgsetAllowMultipleValues()Allow multiple values to be specified for this argument, either as separate arguments or using comma (,) as a delimiter.RequiredArgsetAllowMultipleValues(java.lang.String delimiter)Allow multiple values to be specified for this argument, either as separate arguments or using the specified string as a delimiter.RequiredArgsetDefault(java.lang.String defaultValue)Set a default value for this argument.-
Methods inherited from class com.lmax.simpledsl.api.SimpleDslArg
getAllowedValues, getDefaultValue, getMultipleValueSeparator, getName, isAllowMultipleValues, isRequired, setAllowedValues
-
-
-
-
Method Detail
-
setDefault
public RequiredArg setDefault(java.lang.String defaultValue)
Description copied from class:SimpleDslArgSet 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:
setDefaultin classSimpleDslArg- Parameters:
defaultValue- the default value for the argument.- Returns:
- this argument
-
setAllowedValues
public RequiredArg setAllowedValues(java.lang.String... allowedValues)
Description copied from class:SimpleDslArgRestrict 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:
setAllowedValuesin classSimpleDslArg- Parameters:
allowedValues- the allowable values for this argument.- Returns:
- this argument
-
setAllowMultipleValues
public RequiredArg setAllowMultipleValues()
Description copied from class:SimpleDslArgAllow 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:
setAllowMultipleValuesin classSimpleDslArg- Returns:
- this argument
- See Also:
SimpleDslArg.setAllowMultipleValues(String)
-
setAllowMultipleValues
public RequiredArg setAllowMultipleValues(java.lang.String delimiter)
Description copied from class:SimpleDslArgAllow multiple values to be specified for this argument, either as separate arguments or using the specified string as a delimiter.- Overrides:
setAllowMultipleValuesin classSimpleDslArg- Parameters:
delimiter- the delimiter to use to separate values- Returns:
- this argument
- See Also:
SimpleDslArg.setAllowMultipleValues()
-
-