Class CommandRunner
java.lang.Object
org.springframework.boot.cli.command.CommandRunner
Main class used to run
Commands.- Since:
- 1.0.0
- Author:
- Phillip Webb
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommand(Command command) Add the specified command.voidaddCommands(Iterable<Command> commands) Add the specified commands.protected voidSubclass hook called after a command has run.protected voidSubclass hook called before a command is run.protected booleanerrorMessage(String message) findCommand(String name) Find a command by name.getName()Return the name of the runner or an empty string.booleanisOptionCommand(Command command) Returns if the specified command is an option command.iterator()protected voidprotected ExitStatusParse the arguments and run a suitable command.intrunAndHandleErrors(String... args) Run the appropriate and handle and errors.voidsetHiddenCommands(Class<?>... commandClasses) Set the command classes which should be hidden (i.e.voidsetOptionCommands(Class<?>... commandClasses) Set the command classes which should be considered option commands.protected voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
CommandRunner
Create a newCommandRunnerinstance.- Parameters:
name- the name of the runner ornull
-
-
Method Details
-
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
Add the specified commands.- Parameters:
commands- the commands to add
-
addCommand
Add the specified command.- Parameters:
command- the command to add.
-
setOptionCommands
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:
-
setHiddenCommands
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
Returns if the specified command is an option command.- Parameters:
command- the command to test- Returns:
trueif the command is an option command- See Also:
-
iterator
-
getCommands
-
findCommand
Find a command by name.- Parameters:
name- the name of the command- Returns:
- the command or
nullif not found
-
runAndHandleErrors
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
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
Subclass hook called before a command is run.- Parameters:
command- the command about to run
-
afterRun
Subclass hook called after a command has run.- Parameters:
command- the command that has run
-
errorMessage
-
showUsage
protected void showUsage() -
printStackTrace
-