From a7d9ababa01ccb00a3dc53736c49351147b69460 Mon Sep 17 00:00:00 2001 From: Eric Bottard Date: Wed, 9 Aug 2017 17:43:46 +0200 Subject: [PATCH] Move InputProvider to top-level --- .../org/springframework/shell/InputProvider.java | 16 ++++++++++++++++ .../java/org/springframework/shell/Shell.java | 10 ---------- .../shell/jline/JLineShellAutoConfiguration.java | 3 ++- .../org/springframework/shell/ShellTest.java | 2 +- .../StandardCommandsAutoConfiguration.java | 8 ++++++++ 5 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 spring-shell-core/src/main/java/org/springframework/shell/InputProvider.java diff --git a/spring-shell-core/src/main/java/org/springframework/shell/InputProvider.java b/spring-shell-core/src/main/java/org/springframework/shell/InputProvider.java new file mode 100644 index 00000000..b5035ded --- /dev/null +++ b/spring-shell-core/src/main/java/org/springframework/shell/InputProvider.java @@ -0,0 +1,16 @@ +package org.springframework.shell; + +/** + * To be implemented by components able to provide a "line" of user input, whether interactively or by batch. + * + * @author Eric Bottard + */ +public interface InputProvider { + + /** + * Return text entered by user to invoke commands. + * + *

Returning {@literal null} indicates end of input, requesting shell exit.

+ */ + Input readInput(); +} diff --git a/spring-shell-core/src/main/java/org/springframework/shell/Shell.java b/spring-shell-core/src/main/java/org/springframework/shell/Shell.java index 94e8df6a..5d91d392 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/Shell.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/Shell.java @@ -264,14 +264,4 @@ public class Shell implements CommandRegistry { return "".equals(result) ? null : result; } - public interface InputProvider { - /** - * Return text entered by user to invoke commands. - * - *

Returning {@literal null} indicates end of input, requesting shell exit.

- */ - Input readInput(); - } - - } diff --git a/spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java b/spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java index 6ac56393..b7cc5110 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java @@ -46,6 +46,7 @@ import org.springframework.shell.CompletionContext; import org.springframework.shell.CompletionProposal; import org.springframework.shell.ExitRequest; import org.springframework.shell.Input; +import org.springframework.shell.InputProvider; import org.springframework.shell.ResultHandler; import org.springframework.shell.Shell; @@ -179,7 +180,7 @@ class JLineShellAutoConfiguration { } } - public static class JLineInputProvider implements Shell.InputProvider { + public static class JLineInputProvider implements InputProvider { private final LineReader lineReader; diff --git a/spring-shell-core/src/test/java/org/springframework/shell/ShellTest.java b/spring-shell-core/src/test/java/org/springframework/shell/ShellTest.java index 3623e00e..19ed246a 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/ShellTest.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/ShellTest.java @@ -45,7 +45,7 @@ public class ShellTest { public MockitoRule mockitoRule = MockitoJUnit.rule(); @Mock - private Shell.InputProvider inputProvider; + private InputProvider inputProvider; @Mock private ResultHandler resultHandler; diff --git a/spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/StandardCommandsAutoConfiguration.java b/spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/StandardCommandsAutoConfiguration.java index 04f2cbc5..932835c3 100644 --- a/spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/StandardCommandsAutoConfiguration.java +++ b/spring-shell-standard-commands/src/main/java/org/springframework/shell/standard/commands/StandardCommandsAutoConfiguration.java @@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.shell.ParameterResolver; +import org.springframework.shell.Shell; /** * Creates beans for standard commands. @@ -59,4 +60,11 @@ public class StandardCommandsAutoConfiguration { public Stacktrace stacktrace() { return new Stacktrace(); } + + @Bean + @ConditionalOnMissingBean(Script.Command.class) + @ConditionalOnProperty(prefix = "spring.shell.command.script", value = "enabled", havingValue = "true", matchIfMissing = true) + public Script script(Shell shell) { + return new Script(shell); + } }