Skip to content

Commit 35f1eb5

Browse files
committed
refactor: use common base class default value providing
1 parent 460411c commit 35f1eb5

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

app/src/main/java/com/diffplug/spotless/cli/steps/CustomVersion.java

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

18-
import java.util.Objects;
18+
import java.util.Map;
1919
import java.util.function.Supplier;
2020

2121
import org.jetbrains.annotations.NotNull;
@@ -34,26 +34,9 @@ public class CustomVersion {
3434
description = "The version of ${COMMAND-NAME} to use." + OptionConstants.DEFAULT_VALUE_SUFFIX)
3535
String useVersion;
3636

37-
abstract static class CustomVersionDefaultValueProvider implements CommandLine.IDefaultValueProvider {
38-
private final Supplier<String> defaultVersionSupplier;
39-
37+
abstract static class CustomVersionDefaultValueProvider extends OptionDefaultValueProvider {
4038
protected CustomVersionDefaultValueProvider(@NotNull Supplier<String> defaultVersionSupplier) {
41-
this.defaultVersionSupplier = Objects.requireNonNull(defaultVersionSupplier);
42-
}
43-
44-
@Override
45-
public String defaultValue(CommandLine.Model.ArgSpec argSpec) throws Exception {
46-
// if it is the use-version option, provide the default version, otherwise null
47-
if (!argSpec.isOption()) {
48-
return null;
49-
}
50-
if (!(argSpec instanceof CommandLine.Model.OptionSpec optionSpec)) {
51-
return null;
52-
}
53-
if (!optionSpec.longestName().equals(LONG_OPTION)) {
54-
return null;
55-
}
56-
return defaultVersionSupplier.get();
39+
super(Map.of(LONG_OPTION, defaultVersionSupplier));
5740
}
5841
}
5942
}

0 commit comments

Comments
 (0)