Class AppendArgumentAction
- java.lang.Object
-
- net.sourceforge.argparse4j.impl.action.AppendArgumentAction
-
- All Implemented Interfaces:
ArgumentAction
public class AppendArgumentAction extends java.lang.Object implements ArgumentAction
Argument action to store a list.
This action appends each argument value to the list. The list is of type
List
. This is useful to allow an option to be specified multiple times. Ifattrs
contains non-List object for keyArgument.getDest()
, it will be overwritten by the List containingvalue
.consumeArgument()
always returnstrue
.
-
-
Constructor Summary
Constructors Constructor Description AppendArgumentAction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
consumeArgument()
Returnstrue
if this action consumes argument.void
onAttach(Argument arg)
Called when ArgumentAction is added toArgument
usingArgument.action(ArgumentAction)
.void
run(ArgumentParser parser, Argument arg, java.util.Map<java.lang.String,java.lang.Object> attrs, java.lang.String flag, java.lang.Object value)
Executes this action.void
run(ArgumentParser parser, Argument arg, java.util.Map<java.lang.String,java.lang.Object> attrs, java.lang.String flag, java.lang.Object value, java.util.function.Consumer<java.lang.Object> valueSetter)
Executes this action.
-
-
-
Method Detail
-
run
public void run(ArgumentParser parser, Argument arg, java.util.Map<java.lang.String,java.lang.Object> attrs, java.lang.String flag, java.lang.Object value)
Description copied from interface:ArgumentAction
Executes this action.
If the objects derived from
RuntimeException
are thrown in this method because of invalid input from command line, subclass must catch these exceptions and wrap them inArgumentParserException
and give simple error message to explain what happened briefly.- Specified by:
run
in interfaceArgumentAction
- Parameters:
parser
- The parser.arg
- The argument this action attached to.attrs
- Map to store attributes.flag
- The actual option flag in command line ifarg
is a named arguments.null
ifarg
is a positional argument.value
- The attribute value. This may be null if this action does not consume any arguments.
-
run
public void run(ArgumentParser parser, Argument arg, java.util.Map<java.lang.String,java.lang.Object> attrs, java.lang.String flag, java.lang.Object value, java.util.function.Consumer<java.lang.Object> valueSetter)
Description copied from interface:ArgumentAction
Executes this action.
If the objects derived from
RuntimeException
are thrown in this method because of invalid input from command line, subclass must catch these exceptions and wrap them inArgumentParserException
and give simple error message to explain what happened briefly.- Specified by:
run
in interfaceArgumentAction
- 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 thevalueSetter
with the actual value to be set.flag
- The actual option flag in command line ifarg
is a named arguments.null
ifarg
is 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.
-
consumeArgument
public boolean consumeArgument()
Description copied from interface:ArgumentAction
Returnstrue
if this action consumes argument. Otherwise returnsfalse
.- Specified by:
consumeArgument
in interfaceArgumentAction
- Returns:
true
orfalse
.
-
onAttach
public void onAttach(Argument arg)
Description copied from interface:ArgumentAction
Called when ArgumentAction is added toArgument
usingArgument.action(ArgumentAction)
.- Specified by:
onAttach
in interfaceArgumentAction
- Parameters:
arg
-Argument
object to which this object is added.
-
-