Class CommandScope
execute() is called.
Named similarly to Scope because 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 -
Constructor Summary
ConstructorsConstructorDescriptionCommandScope(String... commandName) Creates a new scope for the given command. -
Method Summary
Modifier and TypeMethodDescriptionaddArgumentValue(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.voidOverwrite the values of any credential-bearing argument keys (perCREDENTIAL_KEY_TOKENS) with"*****"so the original credential Strings stop being referenced by this scope.execute()Executes the command in this scope, and returns the results.<T> TgetArgumentValue(CommandArgumentDefinition<T> argument) Convenience method forgetConfiguredValue(CommandArgumentDefinition), returningConfiguredValue.getValue()along with anyappliedinvalid reference
CommandArgumentDefinition#getValueConverter()Returns theCommandDefinitionfor the command in this scope.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 identifierstatic booleanprovideDependency(Class<?> clazz, Object value) Assign a value to a given provided dependency.setOutput(OutputStream outputStream) Sets the output stream for this command.static voidsuppressExceptionLogging(boolean suppressLoggingFlag) Set flag to turn on/off exception logging, to prevent stack traces from being shown multiple timesvoidvalidate()
-
Field Details
-
DO_NOT_SEND_EXCEPTION_TO_UI
- See Also:
-
SUPPRESS_SHOWING_EXCEPTION_IN_LOG
- See Also:
-
NO_PREFIX_PATTERN
-
-
Constructor Details
-
CommandScope
Creates a new scope for the given command.- Throws:
CommandExecutionException
-
-
Method Details
-
suppressExceptionLogging
public static void suppressExceptionLogging(boolean suppressLoggingFlag) Set flag to turn on/off exception logging, to prevent stack traces from being shown multiple times -
isSuppressExceptionLogging
public static boolean isSuppressExceptionLogging() -
getCommand
Returns theCommandDefinitionfor the command in this scope. -
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
Adds the given key/value pair to the stored argument data.- See Also:
-
addArgumentValue
Adds the given key/value pair to the stored argument data. -
getConfiguredValue
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
Convenience method forgetConfiguredValue(CommandArgumentDefinition), returningConfiguredValue.getValue()along with anyappliedinvalid reference
CommandArgumentDefinition#getValueConverter() -
provideDependency
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
Retrieves the registered dependency object provided by this class identifier -
setOutput
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
- Throws:
CommandValidationException
-
execute
Executes the command in this scope, and returns the results.- Throws:
CommandExecutionException
-
clearCredentialArguments
public void clearCredentialArguments()Overwrite the values of any credential-bearing argument keys (perCREDENTIAL_KEY_TOKENS) with"*****"so the original credential Strings stop being referenced by this scope. Strings are immutable and cannot be wiped in-place, but dropping the reference here makes them GC-eligible (assuming no other references hold the same String) instead of letting them live for the rest of the JVM in long-running embedded scenarios (CWE-316: Cleartext Storage of Sensitive Information in Memory).Caller-invoked. This method must NOT be auto-invoked from
execute()— doing so (as the original CWE-316 fix did) breaks any caller that callsexecute()more than once on the same scope, since the second call reads"*****"instead of the real credential. Callers that reuse a scope (e.g. status-before / update / status-after patterns) must call this method after the finalexecute(), never between executions. Callers that use a scope only once (such as the CLI inMain) typically wrap theexecute()call in a try-finally and call this in thefinally.
-