- All Known Implementing Classes:
AppendArgumentAction,AppendConstArgumentAction,CountArgumentAction,HelpArgumentAction,StoreArgumentAction,StoreConstArgumentAction,StoreFalseArgumentAction,StoreTrueArgumentAction,VersionArgumentAction
public interface ArgumentAction
This interface defines behavior of action when an argument is encountered at
the command line.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif this action consumes argument.voidCalled when ArgumentAction is added toArgumentusingArgument.action(ArgumentAction).voidDeprecated.Does not provide the flexibility to let the parser and/or argument decide how the value is stored.default voidrun(ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag, Object value, Consumer<Object> valueSetter) Executes this action.
-
Method Details
-
run
@Deprecated void run(ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag, Object value) throws ArgumentParserExceptionDeprecated.Does not provide the flexibility to let the parser and/or argument decide how the value is stored.run(ArgumentParser, Argument, Map, String, Object, Consumer)will be called instead. Existing actions should implement that method.Executes this action.
If the objects derived from
RuntimeExceptionare thrown in this method because of invalid input from command line, subclass must catch these exceptions and wrap them inArgumentParserExceptionand give simple error message to explain what happened briefly.- Parameters:
parser- The parser.arg- The argument this action attached to.attrs- Map to store attributes.flag- The actual option flag in command line ifargis a named arguments.nullifargis a positional argument.value- The attribute value. This may be null if this action does not consume any arguments.- Throws:
ArgumentParserException- If error occurred.
-
run
default void run(ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag, Object value, Consumer<Object> valueSetter) throws ArgumentParserExceptionExecutes this action.
If the objects derived from
RuntimeExceptionare thrown in this method because of invalid input from command line, subclass must catch these exceptions and wrap them inArgumentParserExceptionand give simple error message to explain what happened briefly.- Parameters:
parser- The parser.arg- The argument this action attached to.attrs- The current map of attributes. Implementations may read from this map, but may not change it. Implementations must call thevalueSetterwith the actual value to be set.flag- The actual option flag in command line ifargis a named arguments.nullifargis a positional argument.value- The attribute value. This may be null if this action does not consume any arguments.valueSetter- The consumer that will set the actual value determined by this action in the result.- Throws:
ArgumentParserException- If error occurred.
-
onAttach
Called when ArgumentAction is added toArgumentusingArgument.action(ArgumentAction).- Parameters:
arg-Argumentobject to which this object is added.
-
consumeArgument
boolean consumeArgument()Returnstrueif this action consumes argument. Otherwise returnsfalse.- Returns:
trueorfalse.
-