Show an error message when file does not exist for the config-file parameter (#27547)
Closes #26443 Signed-off-by: Martin Bartoš <mabartos@redhat.com>
This commit is contained in:
parent
d12711e858
commit
ee64fb5203
2 changed files with 16 additions and 0 deletions
|
@ -28,6 +28,9 @@ import picocli.CommandLine.Command;
|
|||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.ScopeType;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Command(name = "keycloak",
|
||||
header = {
|
||||
"Keycloak - Open Source Identity and Access Management",
|
||||
|
@ -106,6 +109,10 @@ public final class Main {
|
|||
description = "Set the path to a configuration file. By default, configuration properties are read from the \"keycloak.conf\" file in the \"conf\" directory.",
|
||||
paramLabel = "file")
|
||||
public void setConfigFile(String path) {
|
||||
if (Files.notExists(Path.of(path))) {
|
||||
throw new CommandLine.ParameterException(spec.commandLine(),
|
||||
String.format("File specified via '%s' or '%s' option does not exist.", CONFIG_FILE_LONG_NAME, CONFIG_FILE_SHORT_NAME));
|
||||
}
|
||||
System.setProperty(KeycloakPropertiesConfigSource.KEYCLOAK_CONFIG_FILE_PROP, path);
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.OPTIMIZED_BUILD_OPTION_LONG;
|
||||
import static org.keycloak.quarkus.runtime.cli.command.Main.CONFIG_FILE_LONG_NAME;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.keycloak.it.junit5.extension.CLIResult;
|
||||
|
@ -152,4 +153,12 @@ public class StartCommandDistTest {
|
|||
cliResult = dist.run("start", "--db=dev-mem", "--cache=local", "--hostname=localhost", "--http-enabled=true");
|
||||
cliResult.assertNoMessage("The previous optimized build will be overridden with the following build options:"); // no message, same values provided during auto-build
|
||||
}
|
||||
|
||||
@Test
|
||||
@Launch({CONFIG_FILE_LONG_NAME + "=src/test/resources/non-existing.conf", "start"})
|
||||
void testInvalidConfigFileOption(LaunchResult result) {
|
||||
CLIResult cliResult = (CLIResult) result;
|
||||
cliResult.assertError("File specified via '--config-file' or '-cf' option does not exist.");
|
||||
cliResult.assertError(String.format("Try '%s --help' for more information on the available options.", KeycloakDistribution.SCRIPT_CMD));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue