Add some more smarts around --debug
--verbose seems to be only for CLI logging (so really only for dependency resolution). --debug is interpreted by SpringApplication but up to now has been extracted and deleted from the command line by the CommandRunner. This change makes --debug set a System property *and* pass it down to the application (if used with -- separator). Fixes gh-266
This commit is contained in:
@@ -158,6 +158,9 @@ public class CommandRunner implements Iterable<Command> {
|
||||
public int runAndHandleErrors(String... args) {
|
||||
String[] argsWithoutDebugFlags = removeDebugFlags(args);
|
||||
boolean debug = argsWithoutDebugFlags.length != args.length;
|
||||
if (debug) {
|
||||
System.setProperty("debug", "true");
|
||||
}
|
||||
try {
|
||||
run(argsWithoutDebugFlags);
|
||||
return 0;
|
||||
@@ -173,10 +176,14 @@ public class CommandRunner implements Iterable<Command> {
|
||||
|
||||
private String[] removeDebugFlags(String[] args) {
|
||||
List<String> rtn = new ArrayList<String>(args.length);
|
||||
boolean appArgsDetected = false;
|
||||
for (String arg : args) {
|
||||
if (!("-d".equals(arg) || "--debug".equals(arg))) {
|
||||
rtn.add(arg);
|
||||
// Allow apps to have a -d argument
|
||||
appArgsDetected |= "--".equals(arg);
|
||||
if (("-d".equals(arg) || "--debug".equals(arg)) && !appArgsDetected) {
|
||||
continue;
|
||||
}
|
||||
rtn.add(arg);
|
||||
}
|
||||
return rtn.toArray(new String[rtn.size()]);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ public class RunCommand extends OptionParsingCommand {
|
||||
this.watchOption = option("watch", "Watch the specified file for changes");
|
||||
this.editOption = option(asList("edit", "e"),
|
||||
"Open the file with the default system editor");
|
||||
this.verboseOption = option(asList("verbose", "v"), "Verbose logging");
|
||||
this.verboseOption = option(asList("verbose", "v"),
|
||||
"Verbose logging of dependency resolution");
|
||||
this.quietOption = option(asList("quiet", "q"), "Quiet logging");
|
||||
}
|
||||
|
||||
@@ -141,12 +142,12 @@ public class RunCommand extends OptionParsingCommand {
|
||||
|
||||
@Override
|
||||
public Level getLogLevel() {
|
||||
if (getOptions().has(RunOptionHandler.this.verboseOption)) {
|
||||
return Level.FINEST;
|
||||
}
|
||||
if (getOptions().has(RunOptionHandler.this.quietOption)) {
|
||||
return Level.OFF;
|
||||
}
|
||||
if (getOptions().has(RunOptionHandler.this.verboseOption)) {
|
||||
return Level.FINEST;
|
||||
}
|
||||
return Level.INFO;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user