Class DefaultCommand

  • All Implemented Interfaces:
    Command

    public abstract class DefaultCommand
    extends Object
    implements Command
    Default implementation of Command using annotation to define itself. It is highly recommended to extend this class when implementing a command.

    It defines two hidden Options to create system properties (-Dkey=value) and a way to configure the current working directory.

    • Field Detail

      • systemProperties

        protected List<String> systemProperties
      • executionContext

        protected ExecutionContext executionContext
        The execution context of the command.
    • Constructor Detail

      • DefaultCommand

        public DefaultCommand()
    • Method Detail

      • getCwd

        public File getCwd()
        Returns:
        the configure current working directory. If not set use the "regular" Java current working directory.
      • setCwd

        public void setCwd​(File cwd)
        Sets the current working directory. This method is called when the user configure the "cwd" option as follows: --cwd=the-directory.
        Parameters:
        cwd - the directory
      • setSystemProps

        public void setSystemProps​(List<String> props)
        Gets system properties passed in the user command line. The user can configure system properties using -Dkey=value.
        Parameters:
        props - the properties
      • setUp

        public void setUp​(ExecutionContext ec)
                   throws CLIException
        Description copied from interface: Command
        Set up the command execution environment. The command line model has been retrieved and is frozen. Values has been set / injected. You can use this callback to validate the inputs.
        Specified by:
        setUp in interface Command
        Parameters:
        ec - the context
        Throws:
        CLIException - if the validation failed
      • out

        public PrintStream out()
        Returns:
        the print stream on which message should be written.
      • tearDown

        public void tearDown()
                      throws CLIException
        Description copied from interface: Command
        The command has been executed. Use this method to cleanup the environment.
        Specified by:
        tearDown in interface Command
        Throws:
        CLIException - if anything went wrong
      • applySystemProperties

        protected void applySystemProperties()
        Sets the system properties specified by the user command line.