org.springframework.boot.cli.command

Class CommandRunner

    • Constructor Detail

      • CommandRunner

        public CommandRunner(String name)
        Create a new CommandRunner instance.
        Parameters:
        name - the name of the runner or null
    • Method Detail

      • getName

        public String getName()
        Return the name of the runner or an empty string. Non-empty names will include a trailing space character so that they can be used as a prefix.
        Returns:
        the name of the runner
      • addCommands

        public void addCommands(Iterable<Command> commands)
        Add the specified commands.
        Parameters:
        commands - the commands to add
      • addCommand

        public void addCommand(Command command)
        Add the specified command.
        Parameters:
        command - the command to add.
      • setOptionCommands

        public void setOptionCommands(Class<?>... commandClasses)
        Set the command classes which should be considered option commands. An option command is a special type of command that usually makes more sense to present as if it is an option. For example '--version'.
        Parameters:
        commandClasses - the classes of option commands.
        See Also:
        isOptionCommand(Command)
      • setHiddenCommands

        public void setHiddenCommands(Class<?>... commandClasses)
        Set the command classes which should be hidden (i.e. executed but not displayed in the available commands list).
        Parameters:
        commandClasses - the classes of hidden commands
      • isOptionCommand

        public boolean isOptionCommand(Command command)
        Returns if the specified command is an option command.
        Parameters:
        command - the command to test
        Returns:
        true if the command is an option command
        See Also:
        setOptionCommands(Class...)
      • getCommands

        protected final List<Command> getCommands()
      • findCommand

        public Command findCommand(String name)
        Find a command by name.
        Parameters:
        name - the name of the command
        Returns:
        the command or null if not found
      • runAndHandleErrors

        public int runAndHandleErrors(String... args)
        Run the appropriate and handle and errors.
        Parameters:
        args - the input arguments
        Returns:
        a return status code (non boot is used to indicate an error)
      • run

        protected ExitStatus run(String... args)
                          throws Exception
        Parse the arguments and run a suitable command.
        Parameters:
        args - the arguments
        Returns:
        the outcome of the command
        Throws:
        Exception - if the command fails
      • beforeRun

        protected void beforeRun(Command command)
        Subclass hook called before a command is run.
        Parameters:
        command - the command about to run
      • afterRun

        protected void afterRun(Command command)
        Subclass hook called after a command has run.
        Parameters:
        command - the command that has run
      • errorMessage

        protected boolean errorMessage(String message)
      • showUsage

        protected void showUsage()
      • printStackTrace

        protected void printStackTrace(Exception ex)