Allow overrides of standard commands

This commit is contained in:
Eric Bottard
2017-08-07 13:43:48 +02:00
parent c8e4752119
commit 0ca3dacdce
6 changed files with 66 additions and 4 deletions

View File

@@ -40,6 +40,6 @@ import org.springframework.shell.result.ResultHandlerConfig;
public class SpringShellSample {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(SpringShellSample.class);
ConfigurableApplicationContext context = SpringApplication.run(SpringShellSample.class, args);
}
}

View File

@@ -30,7 +30,20 @@ import org.springframework.shell.standard.ShellMethod;
* @author Eric Bottard
*/
@ShellComponent
public class Console {
public class Clear {
/**
* Marker interface for beans providing {@literal clear} functionality to the shell.
*
* <p>To override the clear command, simply register your own bean implementing that interface
* and the standard implementation will back off.</p>
*
* <p>To disable the {@literal clear} command entirely, set the {@literal spring.shell.command.clear.enabled=false}
* property in the environment.</p>
*
* @author Eric Bottard
*/
public interface Command {}
@Autowired @Lazy
private Terminal terminal;

View File

@@ -49,6 +49,19 @@ import org.springframework.shell.Utils;
@ShellComponent
public class Help {
/**
* Marker interface for beans providing {@literal help} functionality to the shell.
*
* <p>To override the help command, simply register your own bean implementing that interface
* and the standard implementation will back off.</p>
*
* <p>To disable the {@literal help} command entirely, set the {@literal spring.shell.command.help.enabled=false}
* property in the environment.</p>
*
* @author Eric Bottard
*/
public interface Command {}
private final List<ParameterResolver> parameterResolvers;
private CommandRegistry commandRegistry;

View File

@@ -28,6 +28,19 @@ import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class Quit {
/**
* Marker interface for beans providing {@literal quit} functionality to the shell.
*
* <p>To override the quit command, simply register your own bean implementing that interface
* and the standard implementation will back off.</p>
*
* <p>To disable the {@literal quit} command entirely, set the {@literal spring.shell.command.quit.enabled=false}
* property in the environment.</p>
*
* @author Eric Bottard
*/
public interface Command {}
@ShellMethod(help = "Exit the shell.", value = {"quit", "exit"})
public void quit() {
throw new ExitRequest();

View File

@@ -30,6 +30,19 @@ import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class Stacktrace {
/**
* Marker interface for beans providing {@literal stacktrace} functionality to the shell.
*
* <p>To override the stacktrace command, simply register your own bean implementing that interface
* and the standard implementation will back off.</p>
*
* <p>To disable the {@literal stacktrace} command entirely, set the {@literal spring.shell.command.stacktrace.enabled=false}
* property in the environment.</p>
*
* @author Eric Bottard
*/
public interface Command {}
@Autowired @Lazy
private Terminal terminal;

View File

@@ -18,6 +18,8 @@ package org.springframework.shell.standard.commands;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.shell.ParameterResolver;
@@ -31,21 +33,29 @@ import org.springframework.shell.ParameterResolver;
public class StandardCommandsAutoConfiguration {
@Bean
@ConditionalOnMissingBean(Help.Command.class)
@ConditionalOnProperty(prefix = "spring.shell.command.help", value = "enabled", havingValue = "true", matchIfMissing = true)
public Help help(List<ParameterResolver> parameterResolvers) {
return new Help(parameterResolvers);
}
@Bean
public Console console() {
return new Console();
@ConditionalOnMissingBean(Clear.Command.class)
@ConditionalOnProperty(prefix = "spring.shell.command.clear", value = "enabled", havingValue = "true", matchIfMissing = true)
public Clear clear() {
return new Clear();
}
@Bean
@ConditionalOnMissingBean(Quit.Command.class)
@ConditionalOnProperty(prefix = "spring.shell.command.quit", value = "enabled", havingValue = "true", matchIfMissing = true)
public Quit quit() {
return new Quit();
}
@Bean
@ConditionalOnMissingBean(Stacktrace.Command.class)
@ConditionalOnProperty(prefix = "spring.shell.command.stacktrace", value = "enabled", havingValue = "true", matchIfMissing = true)
public Stacktrace stacktrace() {
return new Stacktrace();
}