use of liquibase.exception.CommandValidationException in project liquibase by liquibase.
the class CommandRunner method call.
@Override
public CommandResults call() throws Exception {
List<String> command = new ArrayList<>();
command.add(spec.commandLine().getCommandName());
CommandLine parentCommand = spec.commandLine().getParent();
while (!parentCommand.getCommandName().equals("liquibase")) {
command.add(0, parentCommand.getCommandName());
parentCommand = parentCommand.getParent();
}
final String[] commandName = LiquibaseCommandLine.getCommandNames(spec.commandLine());
for (int i = 0; i < commandName.length; i++) {
commandName[i] = StringUtil.toCamelCase(commandName[i]);
}
final CommandScope commandScope = new CommandScope(commandName);
final File outputFile = LiquibaseCommandLineConfiguration.OUTPUT_FILE.getCurrentValue();
OutputStream outputStream = null;
try {
if (outputFile != null) {
outputStream = new FileOutputStream(outputFile);
commandScope.setOutput(outputStream);
}
return commandScope.execute();
} catch (CommandValidationException cve) {
Throwable cause = cve.getCause();
if (cause instanceof MissingRequiredArgumentException) {
// This is a list of the arguments which the init project command supports. The thinking here is that if the user
// forgets to supply one of these arguments, we're going to remind them about the init project command, which
// can help them figure out what they should be providing here.
final Set<String> initProjectArguments = Stream.of(CommonArgumentNames.CHANGELOG_FILE, CommonArgumentNames.URL, CommonArgumentNames.USERNAME, CommonArgumentNames.PASSWORD).map(CommonArgumentNames::getArgumentName).collect(Collectors.toSet());
throw new CommandValidationException(cve.getMessage() + (initProjectArguments.contains(((MissingRequiredArgumentException) cause).getArgumentName()) ? ". If you need to configure new liquibase project files and arguments, run the 'liquibase init project' command." : ""));
} else {
throw cve;
}
} finally {
if (outputStream != null) {
outputStream.flush();
outputStream.close();
}
}
}
Aggregations