Skip to content

Commit

Permalink
Only NonInteractiveShellRunner is active on default
Browse files Browse the repository at this point in the history
- Disable InteractiveShellRunner and ScriptShellRunner on default
- Enable those in commands and e2e sample apps
- Document changes
- Fixes #1017
  • Loading branch information
jvalkeal committed Mar 10, 2024
1 parent e46ded9 commit cdbbf1d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 the original author or authors.
* Copyright 2021-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,7 +59,7 @@ public NonInteractiveShellRunner nonInteractiveApplicationRunner(Shell shell, Sh
public static class NonePrimaryCommandConfiguration {

@Bean
@ConditionalOnProperty(prefix = "spring.shell.interactive", value = "enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnProperty(prefix = "spring.shell.interactive", value = "enabled", havingValue = "true", matchIfMissing = false)
public InteractiveShellRunner interactiveApplicationRunner(LineReader lineReader, PromptProvider promptProvider,
Shell shell, ShellContext shellContext) {
return new InteractiveShellRunner(lineReader, promptProvider, shell, shellContext);
Expand All @@ -75,7 +75,7 @@ public NonInteractiveShellRunner nonInteractiveApplicationRunner(Shell shell, Sh
}

@Bean
@ConditionalOnProperty(prefix = "spring.shell.script", value = "enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnProperty(prefix = "spring.shell.script", value = "enabled", havingValue = "true", matchIfMissing = false)
public ScriptShellRunner scriptApplicationRunner(Parser parser, Shell shell) {
return new ScriptShellRunner(parser, shell);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,9 +53,10 @@ class ShellRunnerAutoConfigurationTests {

@Nested
class Interactive {

@Test
void enabledByDefault() {
contextRunner.run(context -> assertThat(context).hasSingleBean(InteractiveShellRunner.class));
void disabledByDefault() {
contextRunner.run(context -> assertThat(context).doesNotHaveBean(InteractiveShellRunner.class));
}

@Test
Expand All @@ -67,6 +68,7 @@ void disabledWhenPropertySet() {

@Nested
class NonInteractive {

@Test
void enabledByDefault() {
contextRunner.run(context -> assertThat(context).hasSingleBean(NonInteractiveShellRunner.class));
Expand Down Expand Up @@ -101,9 +103,10 @@ void canBeCustomized() {

@Nested
class Script {

@Test
void enabledByDefault() {
contextRunner.run(context -> assertThat(context).hasSingleBean(ScriptShellRunner.class));
void disabledByDefault() {
contextRunner.run(context -> assertThat(context).doesNotHaveBean(ScriptShellRunner.class));
}

@Test
Expand Down
22 changes: 19 additions & 3 deletions spring-shell-docs/modules/ROOT/pages/execution.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ and its default implementation makes a choice which `ShellRunner` is used. There
only one `ShellApplicationRunner` but it can be redefined if needed for some reason.

Three `ShellRunner` implementation exists, named `InteractiveShellRunner`,
`NonInteractiveShellRunner` and `ScriptShellRunner`. These are enabled on default but
can be disable if needed using properties `spring.shell.interactive.enabled`,
`spring.shell.noninteractive.enabled` and `spring.shell.script.enabled` respecively.
`NonInteractiveShellRunner` and `ScriptShellRunner`. Only `NonInteractiveShellRunner`
is enabled by default. Enabled state can be modified using properties
`spring.shell.interactive.enabled`, `spring.shell.noninteractive.enabled` and
`spring.shell.script.enabled` respecively.

For example enabling interactive and script runners use properties:

[source, yaml]
----
spring:
shell:
interactive:
enabled: true
script:
enabled: true
----

NOTE: Versions up to `3.2.x` had all runners enabled by default, starting from `3.3.x`
only `NonInteractiveShellRunner` is enabled by default.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ spring:
main:
banner-mode: off
shell:
interactive:
enabled: true
## pick global default option naming
# option:
# naming:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ spring:
main:
banner-mode: off
shell:
interactive:
enabled: true
## pick global default option naming
# option:
# naming:
Expand Down

0 comments on commit cdbbf1d

Please sign in to comment.