diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java index b0c766ca47..1cb7439ec5 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java @@ -188,9 +188,9 @@ public class CommandRunner implements Iterable { List rtn = new ArrayList<>(args.length); boolean appArgsDetected = false; for (String arg : args) { - // Allow apps to have a -d argument + // Allow apps to have a --debug argument appArgsDetected |= "--".equals(arg); - if (("-d".equals(arg) || "--debug".equals(arg)) && !appArgsDetected) { + if ("--debug".equals(arg) && !appArgsDetected) { continue; } rtn.add(arg); @@ -284,7 +284,7 @@ public class CommandRunner implements Iterable { } Log.info(""); Log.info("Common options:"); - Log.info(String.format("%n %1$s %2$-15s%n %3$s", "-d, --debug", "Verbose mode", + Log.info(String.format("%n %1$s %2$-15s%n %3$s", "--debug", "Verbose mode", "Print additional status information for the command you are running")); Log.info(""); Log.info(""); diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerIntegrationTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerIntegrationTests.java index b069fad5ed..7cb4dcca7e 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerIntegrationTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerIntegrationTests.java @@ -16,12 +16,10 @@ package org.springframework.boot.cli.command; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.boot.cli.command.run.RunCommand; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.boot.cli.command.status.ExitStatus; import static org.assertj.core.api.Assertions.assertThat; @@ -29,26 +27,49 @@ import static org.assertj.core.api.Assertions.assertThat; * Integration tests for {@link CommandRunner}. * * @author Dave Syer + * @author Andy Wilkinson */ -@ExtendWith(OutputCaptureExtension.class) class CommandRunnerIntegrationTests { - @Test - void debugAddsAutoconfigReport(CapturedOutput capturedOutput) { - CommandRunner runner = new CommandRunner("spring"); - runner.addCommand(new RunCommand()); - // -d counts as "debug" for the spring command, but not for the - // LoggingApplicationListener - runner.runAndHandleErrors("run", "samples/app.groovy", "-d"); - assertThat(capturedOutput).contains("Negative matches:"); + @BeforeEach + void clearDebug() { + System.clearProperty("debug"); } @Test - void debugSwitchedOffForAppArgs(CapturedOutput capturedOutput) { + void debugEnabledAndArgumentRemovedWhenNotAnApplicationArgument() { CommandRunner runner = new CommandRunner("spring"); - runner.addCommand(new RunCommand()); - runner.runAndHandleErrors("run", "samples/app.groovy", "--", "-d"); - assertThat(capturedOutput).doesNotContain("Negative matches:"); + ArgHandlingCommand command = new ArgHandlingCommand(); + runner.addCommand(command); + runner.runAndHandleErrors("args", "samples/app.groovy", "--debug"); + assertThat(command.args).containsExactly("samples/app.groovy"); + assertThat(System.getProperty("debug")).isEqualTo("true"); + } + + @Test + void debugNotEnabledAndArgumentRetainedWhenAnApplicationArgument() { + CommandRunner runner = new CommandRunner("spring"); + ArgHandlingCommand command = new ArgHandlingCommand(); + runner.addCommand(command); + runner.runAndHandleErrors("args", "samples/app.groovy", "--", "--debug"); + assertThat(command.args).containsExactly("samples/app.groovy", "--", "--debug"); + assertThat(System.getProperty("debug")).isNull(); + } + + static class ArgHandlingCommand extends AbstractCommand { + + private String[] args; + + ArgHandlingCommand() { + super("args", ""); + } + + @Override + public ExitStatus run(String... args) throws Exception { + this.args = args; + return ExitStatus.OK; + } + } } diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java index c91049a6c1..f26c8c35de 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java @@ -147,15 +147,6 @@ class CommandRunnerTests { assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE); } - @Test - void handlesExceptionWithDashD() throws Exception { - willThrow(new RuntimeException()).given(this.regularCommand).run(); - int status = this.commandRunner.runAndHandleErrors("command", "-d"); - assertThat(System.getProperty("debug")).isEqualTo("true"); - assertThat(status).isEqualTo(1); - assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE); - } - @Test void handlesExceptionWithDashDashDebug() throws Exception { willThrow(new RuntimeException()).given(this.regularCommand).run();