Skip to content

Commit 2fa36a7

Browse files
committed
Revert "refactor: extract logging config into mixin"
This reverts commit 8eb62e7.
1 parent 8eb62e7 commit 2fa36a7

File tree

3 files changed

+45
-77
lines changed

3 files changed

+45
-77
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ Runs spotless
126126
-p, --parallelity=N The number of parallel formatter threads to run.
127127
(default: #cores * 0.5)
128128
-q, --quiet Disable as much output as possible.
129-
-q, --quiet Disable as much output as possible.
130129
-t, --target=<targets> The target files to format.
131-
-v Enable verbose output. Multiple -v options
132-
increase the verbosity (max 5).
133130
-v Enable verbose output. Multiple -v options
134131
increase the verbosity (max 5).
135132
-V, --version Print version information and exit.

app/src/main/java/com/diffplug/spotless/cli/LoggingOptions.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

app/src/main/java/com/diffplug/spotless/cli/SpotlessCLI.java

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.diffplug.spotless.cli;
1717

18+
import java.io.File;
1819
import java.nio.charset.Charset;
1920
import java.nio.file.Path;
2021
import java.util.List;
@@ -118,16 +119,55 @@ public void setParallelity(int parallelity) {
118119
this.parallelity = parallelity;
119120
}
120121

121-
@CommandLine.Mixin
122-
LoggingOptions loggingOptions;
122+
@CommandLine.ArgGroup(exclusive = true, multiplicity = "0..1")
123+
LoggingLevelOptions loggingLevelOptions;
124+
125+
class LoggingLevelOptions {
126+
127+
private boolean[] verbosity;
128+
129+
@CommandLine.Option(
130+
names = {"-v"},
131+
description = "Enable verbose output. Multiple -v options increase the verbosity (max 5).",
132+
arity = "0")
133+
public void setVerbose(boolean[] verbosity) {
134+
if (verbosity.length > 5) {
135+
throw new CommandLine.ParameterException(
136+
spec.commandLine(), "Error: --verbose can be used at most 5 times");
137+
}
138+
this.verbosity = verbosity;
139+
}
140+
141+
@CommandLine.Option(
142+
names = {"--quiet", "-q"},
143+
description = "Disable as much output as possible.",
144+
arity = "0")
145+
boolean quiet;
146+
147+
LoggingConfigurer.CLIOutputLevel toCliOutputLevel() {
148+
if (quiet) {
149+
return LoggingConfigurer.CLIOutputLevel.QUIET;
150+
}
151+
if (verbosity == null) {
152+
return LoggingConfigurer.CLIOutputLevel.DEFAULT;
153+
}
154+
int verbosityCount = this.verbosity.length;
155+
return LoggingConfigurer.CLIOutputLevel.verbosity(verbosityCount);
156+
}
157+
}
158+
159+
@CommandLine.Option(
160+
names = {"--log-file"},
161+
description = "The log file to write the output to.")
162+
File logFile;
123163

124164
@Override
125165
public void setupLogging() {
126166
LoggingConfigurer.configureLogging(
127-
loggingOptions.loggingLevelOptions != null
128-
? loggingOptions.loggingLevelOptions.toCliOutputLevel()
167+
loggingLevelOptions != null
168+
? loggingLevelOptions.toCliOutputLevel()
129169
: LoggingConfigurer.CLIOutputLevel.DEFAULT,
130-
loggingOptions.logFile);
170+
logFile);
131171
}
132172

133173
@Override

0 commit comments

Comments
 (0)