use of com.google.copybara.util.TablePrinter in project copybara by google.
the class InfoCmd method showAllMigrations.
private static void showAllMigrations(CommandEnv commandEnv, Config config) {
TablePrinter table = new TablePrinter("Name", "Origin", "Destination", "Mode", "Description");
for (Migration m : config.getMigrations().values().stream().sorted(Comparator.comparing(Migration::getName)).collect(ImmutableList.toImmutableList())) {
table.addRow(m.getName(), prettyOriginDestination(m.getOriginDescription()), prettyOriginDestination(m.getDestinationDescription()), m.getModeString(), Strings.nullToEmpty(m.getDescription()));
}
Console console = commandEnv.getOptions().get(GeneralOptions.class).console();
for (String line : table.build()) {
console.info(line);
}
console.info("To get information about the state of any migration run:\n\n" + " copybara info " + config.getLocation() + " [workflow_name]" + "\n");
}
use of com.google.copybara.util.TablePrinter in project copybara by google.
the class InfoCmd method info.
/**
* Retrieves the {@link Info} of the {@code migrationName} and prints it to the console.
*/
private static void info(Options options, Config config, String migrationName, ImmutableMap<String, String> context) throws ValidationException, RepoException {
Info<? extends Revision> info = getInfo(migrationName, config);
Console console = options.get(GeneralOptions.class).console();
int outputSize = 0;
for (MigrationReference<? extends Revision> migrationRef : info.migrationReferences()) {
console.info(String.format("'%s': last_migrated %s - last_available %s.", migrationRef.getLabel(), migrationRef.getLastMigrated() != null ? migrationRef.getLastMigrated().asString() : "None", migrationRef.getLastAvailableToMigrate() != null ? migrationRef.getLastAvailableToMigrate().asString() : "None"));
ImmutableList<? extends Change<? extends Revision>> availableToMigrate = migrationRef.getAvailableToMigrate();
int outputLimit = options.get(GeneralOptions.class).getOutputLimit();
if (!availableToMigrate.isEmpty()) {
console.infoFmt("Available changes %s:", availableToMigrate.size() <= outputLimit ? String.format("(%d)", availableToMigrate.size()) : String.format("(showing only first %d out of %d)", outputLimit, availableToMigrate.size()));
TablePrinter table = new TablePrinter("Date", "Revision", "Description", "Author");
for (Change<? extends Revision> change : Iterables.limit(availableToMigrate, outputLimit)) {
outputSize++;
table.addRow(change.getDateTime().format(DATE_FORMATTER), Ascii.truncate(change.getRevision().asString(), REVISION_MAX_LENGTH, ""), Ascii.truncate(change.firstLineMessage(), DESCRIPTION_MAX_LENGTH, "..."), Ascii.truncate(change.getAuthor().toString(), AUTHOR_MAX_LENGTH, "..."));
}
for (String line : table.build()) {
console.info(line);
}
}
if (outputSize > 100) {
console.infoFmt("Use %s to limit the output of the command.", GeneralOptions.OUTPUT_LIMIT_FLAG);
}
}
options.get(GeneralOptions.class).eventMonitors().dispatchEvent(e -> e.onInfoFinished(new InfoFinishedEvent(info, context)));
}
Aggregations