Class CommandRunner
java.lang.Object
org.springframework.boot.cli.command.CommandRunner
Main class used to run
Command
s.- Since:
- 1.0.0
- Author:
- Phillip Webb
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCommand
(Command command) Add the specified command.void
addCommands
(Iterable<Command> commands) Add the specified commands.protected void
Subclass hook called after a command has run.protected void
Subclass hook called before a command is run.protected boolean
errorMessage
(String message) findCommand
(String name) Find a command by name.getName()
Return the name of the runner or an empty string.boolean
isOptionCommand
(Command command) Returns if the specified command is an option command.iterator()
protected void
protected ExitStatus
Parse the arguments and run a suitable command.int
runAndHandleErrors
(String... args) Run the appropriate and handle and errors.void
setHiddenCommands
(Class<?>... commandClasses) Set the command classes which should be hidden (i.e.void
setOptionCommands
(Class<?>... commandClasses) Set the command classes which should be considered option commands.protected void
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
CommandRunner
Create a newCommandRunner
instance.- 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:
true
if 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
null
if 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
-