类 CommandRunner
- java.lang.Object
- org.springframework.boot.cli.command.CommandRunner
public class CommandRunner extends Object implements Iterable<Command>
Main class used to runCommands.
构造器概要
构造器 构造器 说明 CommandRunner(String name)Create a newCommandRunnerinstance.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidaddCommand(Command command)Add the specified command.voidaddCommands(Iterable<Command> commands)Add the specified commands.protected voidafterRun(Command command)Subclass hook called after a command has run.protected voidbeforeRun(Command command)Subclass hook called before a command is run.protected booleanerrorMessage(String message)CommandfindCommand(String name)Find a command by name.protected List<Command>getCommands()StringgetName()Return the name of the runner or an empty string.booleanisOptionCommand(Command command)Returns if the specified command is an option command.Iterator<Command>iterator()protected voidprintStackTrace(Exception ex)protected ExitStatusrun(String... args)Parse 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. executed but not displayed in the available commands list).voidsetOptionCommands(Class<?>... commandClasses)Set the command classes which should be considered option commands.protected voidshowUsage()从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 java.lang.Iterable
forEach, spliterator
构造器详细资料
CommandRunner
public CommandRunner(String name)
Create a newCommandRunnerinstance.- 参数:
name- the name of the runner ornull
方法详细资料
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.- 返回:
- the name of the runner
addCommands
public void addCommands(Iterable<Command> commands)
Add the specified commands.- 参数:
commands- the commands to add
addCommand
public void addCommand(Command command)
Add the specified command.- 参数:
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'.- 参数:
commandClasses- the classes of option commands.- 另请参阅:
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).- 参数:
commandClasses- the classes of hidden commands
isOptionCommand
public boolean isOptionCommand(Command command)
Returns if the specified command is an option command.- 参数:
command- the command to test- 返回:
trueif the command is an option command- 另请参阅:
setOptionCommands(Class...)
getCommands
protected final List<Command> getCommands()
findCommand
public Command findCommand(String name)
Find a command by name.- 参数:
name- the name of the command- 返回:
- the command or
nullif not found
runAndHandleErrors
public int runAndHandleErrors(String... args)
Run the appropriate and handle and errors.- 参数:
args- the input arguments- 返回:
- 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.- 参数:
args- the arguments- 返回:
- the outcome of the command
- 抛出:
Exception- if the command fails
beforeRun
protected void beforeRun(Command command)
Subclass hook called before a command is run.- 参数:
command- the command about to run
afterRun
protected void afterRun(Command command)
Subclass hook called after a command has run.- 参数:
command- the command that has run
errorMessage
protected boolean errorMessage(String message)
showUsage
protected void showUsage()
printStackTrace
protected void printStackTrace(Exception ex)