Class StoreConstArgumentAction

  • All Implemented Interfaces:
    ArgumentAction

    public class StoreConstArgumentAction
    extends java.lang.Object
    implements ArgumentAction

    Argument action to store the value specified by the Argument.setConst(Object).

    Note that by default const value is null. This action is most commonly used with named arguments that specify sort of flags. consumeArgument() always returns false.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean consumeArgument()
      Returns true if this action consumes argument.
      void onAttach​(Argument arg)
      Called when ArgumentAction is added to Argument using Argument.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StoreConstArgumentAction

        public StoreConstArgumentAction()
    • 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 in ArgumentParserException and give simple error message to explain what happened briefly.

        Specified by:
        run in interface ArgumentAction
        Parameters:
        parser - The parser.
        arg - The argument this action attached to.
        attrs - Map to store attributes.
        flag - The actual option flag in command line if arg is a named arguments. null if arg 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 in ArgumentParserException and give simple error message to explain what happened briefly.

        Specified by:
        run in interface ArgumentAction
        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 the valueSetter with the actual value to be set.
        flag - The actual option flag in command line if arg is a named arguments. null if arg 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
        Returns true if this action consumes argument. Otherwise returns false.
        Specified by:
        consumeArgument in interface ArgumentAction
        Returns:
        true or false.