use of liquibase.ui.UIService in project liquibase by liquibase.
the class RegisterChangelogCommandStep method readProjectFromConsole.
private String readProjectFromConsole(List<Project> projects, String changeLogFile) throws CommandLineParsingException {
final UIService ui = Scope.getCurrentScope().getUI();
StringBuilder prompt = new StringBuilder("Registering a changelog connects Liquibase operations to a Project for monitoring and reporting.\n");
prompt.append("Register changelog " + changeLogFile + " to an existing Project, or create a new one.\n");
prompt.append("Please make a selection:\n");
prompt.append("[c] Create new Project\n");
String projFormat = "[%d]";
if (projects.size() >= 10 && projects.size() < 100) {
projFormat = "[%2d]";
} else if (projects.size() >= 100 && projects.size() < 1000) {
projFormat = "[%3d]";
} else if (projects.size() >= 1000 && projects.size() < 10000) {
projFormat = "[%4d]";
}
int maxLen = 40;
for (Project project : projects) {
if (project.getName() != null && project.getName().length() > maxLen) {
maxLen = project.getName().length();
}
}
for (int i = 0; i < projects.size(); i++) {
Project project = projects.get(i);
prompt.append(String.format(projFormat + " %-" + maxLen + "s (Project ID:%s) %s\n", i + 1, project.getName(), projects.get(i).getId(), projects.get(i).getCreateDate()));
}
prompt.append("[N] to not register this changelog right now.\n" + "You can still run Liquibase commands, but no data will be saved in your Liquibase Hub account for monitoring or reports.\n" + " Learn more at https://hub.liquibase.com.\n?");
return StringUtil.trimToEmpty(ui.prompt(prompt.toString(), "N", null, String.class));
}
use of liquibase.ui.UIService in project liquibase by liquibase.
the class RegisterChangelogCommandStep method readProjectNameFromConsole.
private String readProjectNameFromConsole() throws CommandLineParsingException {
final UIService ui = Scope.getCurrentScope().getUI();
String hubUrl = HubConfiguration.LIQUIBASE_HUB_URL.getCurrentValue();
String input = ui.prompt("Please enter your Project name and press [enter]. This is editable in your Liquibase Hub account at " + hubUrl, null, null, String.class);
return StringUtil.trimToEmpty(input);
}
use of liquibase.ui.UIService in project liquibase by liquibase.
the class LiquibaseCommandLine method configureScope.
/**
* Configures the system, and returns values to add to Scope.
*
* @return values to set in the scope
*/
private Map<String, Object> configureScope() throws Exception {
Map<String, Object> returnMap = new HashMap<>();
final ClassLoader classLoader = configureClassLoader();
returnMap.putAll(configureLogging());
returnMap.putAll(configureResourceAccessor(classLoader));
ConsoleUIService ui = null;
List<UIService> uiServices = Scope.getCurrentScope().getServiceLocator().findInstances(UIService.class);
for (UIService uiService : uiServices) {
if (uiService instanceof ConsoleUIService) {
ui = (ConsoleUIService) uiService;
break;
}
}
if (ui == null) {
ui = new ConsoleUIService();
}
ui.setAllowPrompt(true);
ui.setOutputStream(System.err);
returnMap.put(Scope.Attr.ui.name(), ui);
returnMap.put(LiquibaseCommandLineConfiguration.ARGUMENT_CONVERTER.getKey(), (LiquibaseCommandLineConfiguration.ArgumentConverter) argument -> "--" + StringUtil.toKabobCase(argument));
return returnMap;
}
use of liquibase.ui.UIService in project liquibase by liquibase.
the class RegisterChangelogCommandStep method retrieveOrCreateProject.
private Project retrieveOrCreateProject(HubService service, String changeLogFile, boolean skipPromptIfOneProject) throws CommandLineParsingException, LiquibaseException, LiquibaseHubException {
final UIService ui = Scope.getCurrentScope().getUI();
Project project = null;
List<Project> projects = getProjectsFromHub();
if (skipPromptIfOneProject && projects.size() == 1) {
return projects.get(0);
}
boolean done = false;
String input = null;
while (!done) {
input = readProjectFromConsole(projects, changeLogFile);
try {
if (input.equalsIgnoreCase("C")) {
String projectName = readProjectNameFromConsole();
if (StringUtil.isEmpty(projectName)) {
ui.sendMessage("\nNo project created\n");
continue;
} else if (projectName.length() > 255) {
ui.sendMessage("\nThe project name you entered is longer than 255 characters\n");
continue;
}
project = service.createProject(new Project().setName(projectName));
if (project == null) {
throw new CommandExecutionException("Unable to create project '" + projectName + "'.\n\n");
}
ui.sendMessage("\nProject '" + project.getName() + "' created with project ID '" + project.getId() + "'.\n");
projects = getProjectsFromHub();
done = true;
continue;
} else if (input.equalsIgnoreCase("N")) {
throw new CommandExecutionException("Your changelog " + changeLogFile + " was not registered to any Liquibase Hub project. You can still run Liquibase commands, but no data will be saved in your Liquibase Hub account for monitoring or reports. Learn more at https://hub.liquibase.com.");
}
int projectIdx = Integer.parseInt(input);
if (projectIdx > 0 && projectIdx <= projects.size()) {
project = projects.get(projectIdx - 1);
if (project != null) {
done = true;
}
} else {
ui.sendMessage("\nInvalid project '" + projectIdx + "' selected\n");
}
} catch (NumberFormatException nfe) {
ui.sendMessage("\nInvalid selection '" + input + "'\n");
}
}
return project;
}
Aggregations