Fix NonInteractiveShellRunner for empty args

- Fix issue when empty args resulted runner to
  think it should handle this scenario effectively
  hijacking interactive mode.
- This bug were added by previous rework on #372
This commit is contained in:
Janne Valkealahti
2022-02-22 09:47:20 +00:00
parent 0a074b37e4
commit 114dbeccaa
2 changed files with 42 additions and 3 deletions

View File

@@ -58,14 +58,14 @@ public class NonInteractiveShellRunner implements ShellRunner {
private Parser lineParser;
private Function<ApplicationArguments, List<String>> commandsFromInputArgs;
private Function<ApplicationArguments, List<String>> commandsFromInputArgs = args -> args
.getSourceArgs().length == 0 ? Collections.emptyList()
: Collections.singletonList(String.join(" ", args.getSourceArgs()));
public NonInteractiveShellRunner(Shell shell, ShellContext shellContext) {
this.shell = shell;
this.shellContext = shellContext;
this.lineParser = new DefaultParser();
this.commandsFromInputArgs = (args) ->
Collections.singletonList(String.join(" ", args.getSourceArgs()));
}
/**

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2022 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.jline;
import org.junit.jupiter.api.Test;
import org.springframework.boot.DefaultApplicationArguments;
import static org.assertj.core.api.Assertions.assertThat;
public class NonInteractiveShellRunnerTests {
@Test
public void testEmptyArgsDontRun() {
NonInteractiveShellRunner runner = new NonInteractiveShellRunner(null, null);
DefaultApplicationArguments args = new DefaultApplicationArguments();
assertThat(runner.canRun(args)).isFalse();
}
@Test
public void testNonEmptyArgsRun() {
NonInteractiveShellRunner runner = new NonInteractiveShellRunner(null, null);
DefaultApplicationArguments args = new DefaultApplicationArguments("hi");
assertThat(runner.canRun(args)).isTrue();
}
}