|
15 | 15 | */ |
16 | 16 | package com.diffplug.spotless.cli; |
17 | 17 |
|
| 18 | +import java.io.File; |
18 | 19 | import java.nio.charset.Charset; |
19 | 20 | import java.nio.file.Path; |
20 | 21 | import java.util.List; |
@@ -118,16 +119,55 @@ public void setParallelity(int parallelity) { |
118 | 119 | this.parallelity = parallelity; |
119 | 120 | } |
120 | 121 |
|
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; |
123 | 163 |
|
124 | 164 | @Override |
125 | 165 | public void setupLogging() { |
126 | 166 | LoggingConfigurer.configureLogging( |
127 | | - loggingOptions.loggingLevelOptions != null |
128 | | - ? loggingOptions.loggingLevelOptions.toCliOutputLevel() |
| 167 | + loggingLevelOptions != null |
| 168 | + ? loggingLevelOptions.toCliOutputLevel() |
129 | 169 | : LoggingConfigurer.CLIOutputLevel.DEFAULT, |
130 | | - loggingOptions.logFile); |
| 170 | + logFile); |
131 | 171 | } |
132 | 172 |
|
133 | 173 | @Override |
|
0 commit comments