Fix color option

This commit is contained in:
Guillaume Nodet
2024-11-25 10:01:48 +01:00
parent e4828fdf98
commit 8fa060e7a7

View File

@@ -588,7 +588,18 @@ public enum Environment {
auto;
public static Optional<Color> of(String color) {
return color == null ? Optional.empty() : Optional.of(Color.valueOf(color));
if (color == null) {
return Optional.empty();
} else if ("always".equals(color) || "yes".equals(color) || "force".equals(color)) {
return Optional.of(Color.always);
} else if ("never".equals(color) || "no".equals(color) || "none".equals(color)) {
return Optional.of(Color.never);
} else if ("auto".equals(color) || "tty".equals(color) || "if-tty".equals(color)) {
return Optional.of(Color.auto);
} else {
throw new IllegalArgumentException(
"Invalid color configuration value '" + color + "'. Supported are 'auto', 'always', 'never'.");
}
}
}