Package liquibase.command
Class CommandScope
- java.lang.Object
-
- liquibase.command.CommandScope
-
public class CommandScope extends Object
The primary facade used for executing commands. This object gets configured with the command to run and the input arguments associated with it, then is populated with the result output afterexecute()is called.Named similarly to
Scopebecause they both define a self-contained unit of values, but this scope is specific to a command rather than being a global scope.
-
-
Field Summary
Fields Modifier and Type Field Description static PatternNO_PREFIX_PATTERN
-
Constructor Summary
Constructors Constructor Description CommandScope(String... commandName)Creates a new scope for the given command.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandScopeaddArgumentValue(String argument, Object value)Adds the given key/value pair to the stored argument data.<T> CommandScopeaddArgumentValue(CommandArgumentDefinition<T> argument, T value)Adds the given key/value pair to the stored argument data.CommandResultsexecute()Executes the command in this scope, and returns the results.<T> TgetArgumentValue(CommandArgumentDefinition<T> argument)Convenience method forgetConfiguredValue(CommandArgumentDefinition), returningConfiguredValue.getValue()along with anyCommandArgumentDefinition.getValueConverter()appliedCommandDefinitiongetCommand()Returns theCommandDefinitionfor the command in this scope.StringgetCompleteConfigPrefix()Returns the complete configuration prefix (without a trailing period) for the command in this scope.<T> ConfiguredValue<T>getConfiguredValue(CommandArgumentDefinition<T> argument)Returns the detailed information about how an argument is set.<T> ObjectgetDependency(Class<T> clazz)Retrieves the registered dependency object provided by this class identifierCommandScopeprovideDependency(Class<?> clazz, Object value)Assign a value to a given provided dependency.CommandScopesetOutput(OutputStream outputStream)Sets the output stream for this command.voidvalidate()
-
-
-
Field Detail
-
NO_PREFIX_PATTERN
public static final Pattern NO_PREFIX_PATTERN
-
-
Constructor Detail
-
CommandScope
public CommandScope(String... commandName) throws CommandExecutionException
Creates a new scope for the given command.- Throws:
CommandExecutionException
-
-
Method Detail
-
getCommand
public CommandDefinition getCommand()
Returns theCommandDefinitionfor the command in this scope.
-
getCompleteConfigPrefix
public String getCompleteConfigPrefix()
Returns the complete configuration prefix (without a trailing period) for the command in this scope.- Returns:
- the complete configuration prefix for the command in this scope
-
addArgumentValue
public CommandScope addArgumentValue(String argument, Object value)
Adds the given key/value pair to the stored argument data.- See Also:
for a type-safe version
-
addArgumentValue
public <T> CommandScope addArgumentValue(CommandArgumentDefinition<T> argument, T value)
Adds the given key/value pair to the stored argument data.
-
getConfiguredValue
public <T> ConfiguredValue<T> getConfiguredValue(CommandArgumentDefinition<T> argument)
Returns the detailed information about how an argument is set.
Prefers values set withaddArgumentValue(String, Object), but will also checkLiquibaseConfigurationfor settings of liquibase.command.${commandName(s)}.${argumentName} or liquibase.command.${argumentName}
-
getArgumentValue
public <T> T getArgumentValue(CommandArgumentDefinition<T> argument)
Convenience method forgetConfiguredValue(CommandArgumentDefinition), returningConfiguredValue.getValue()along with anyCommandArgumentDefinition.getValueConverter()applied
-
provideDependency
public CommandScope provideDependency(Class<?> clazz, Object value)
Assign a value to a given provided dependency. So if a CommandStep provides class X, atCommandStep.run(CommandResultsBuilder)method it needs to provide the value for X using this method. commandScope.provideDependency(LockService.class, lockService);Means that this class will LockService.class using object lock
-
getDependency
public <T> Object getDependency(Class<T> clazz)
Retrieves the registered dependency object provided by this class identifier
-
setOutput
public CommandScope setOutput(OutputStream outputStream)
Sets the output stream for this command. The command output sent to this stream should not include status/progress type output, only the actual output itself. Think "what would be piped out", not "what the user is told about what is happening".
-
validate
public void validate() throws CommandValidationException- Throws:
CommandValidationException
-
execute
public CommandResults execute() throws CommandExecutionException
Executes the command in this scope, and returns the results.- Throws:
CommandExecutionException
-
-