Drop -d option from CLI as it was not POSIX compliant

Closes gh-16663
pull/17462/head
Andy Wilkinson 5 years ago
parent 7536d88ece
commit 9f253603db

@ -188,9 +188,9 @@ public class CommandRunner implements Iterable<Command> {
List<String> 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<Command> {
}
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("");

@ -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 {
@BeforeEach
void clearDebug() {
System.clearProperty("debug");
}
@Test
void debugAddsAutoconfigReport(CapturedOutput capturedOutput) {
void debugEnabledAndArgumentRemovedWhenNotAnApplicationArgument() {
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:");
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 debugSwitchedOffForAppArgs(CapturedOutput capturedOutput) {
void debugNotEnabledAndArgumentRetainedWhenAnApplicationArgument() {
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", "--", "--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;
}
}
}

@ -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();

Loading…
Cancel
Save