|
| 1 | +/* |
| 2 | + * Copyright 2024 DiffPlug |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.diffplug.spotless.cli; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | + |
| 20 | +import com.diffplug.spotless.cli.logging.output.LoggingConfigurer; |
| 21 | + |
| 22 | +import picocli.CommandLine; |
| 23 | + |
| 24 | +class LoggingOptions { |
| 25 | + |
| 26 | + @CommandLine.ArgGroup(exclusive = true, multiplicity = "0..1") |
| 27 | + LoggingLevelOptions loggingLevelOptions; |
| 28 | + |
| 29 | + static class LoggingLevelOptions { |
| 30 | + @CommandLine.Spec(CommandLine.Spec.Target.MIXEE) |
| 31 | + CommandLine.Model.CommandSpec spec; |
| 32 | + |
| 33 | + private boolean[] verbosity; |
| 34 | + |
| 35 | + @CommandLine.Option( |
| 36 | + names = {"-v"}, |
| 37 | + description = "Enable verbose output. Multiple -v options increase the verbosity (max 5).", |
| 38 | + arity = "0") |
| 39 | + public void setVerbose(boolean[] verbosity) { |
| 40 | + if (verbosity.length > 5) { |
| 41 | + throw new CommandLine.ParameterException( |
| 42 | + spec.commandLine(), "Error: --verbose can be used at most 5 times"); |
| 43 | + } |
| 44 | + this.verbosity = verbosity; |
| 45 | + } |
| 46 | + |
| 47 | + @CommandLine.Option( |
| 48 | + names = {"--quiet", "-q"}, |
| 49 | + description = "Disable as much output as possible.", |
| 50 | + arity = "0") |
| 51 | + boolean quiet; |
| 52 | + |
| 53 | + LoggingConfigurer.CLIOutputLevel toCliOutputLevel() { |
| 54 | + if (quiet) { |
| 55 | + return LoggingConfigurer.CLIOutputLevel.QUIET; |
| 56 | + } |
| 57 | + if (verbosity == null) { |
| 58 | + return LoggingConfigurer.CLIOutputLevel.DEFAULT; |
| 59 | + } |
| 60 | + int verbosityCount = this.verbosity.length; |
| 61 | + return LoggingConfigurer.CLIOutputLevel.verbosity(verbosityCount); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + @CommandLine.Option( |
| 66 | + names = {"--log-file"}, |
| 67 | + description = "The log file to write the output to.") |
| 68 | + File logFile; |
| 69 | +} |
0 commit comments