Search in sources :

Example 1 with ColumnFormatter

use of com.google.gerrit.server.ioutil.ColumnFormatter in project gerrit by GerritCodeReview.

the class ListGroupsCommand method run.

@Override
public void run() throws Exception {
    enableGracefulStop();
    if (listGroups.getUser() != null && !listGroups.getProjects().isEmpty()) {
        throw die("--user and --project options are not compatible.");
    }
    ColumnFormatter formatter = new ColumnFormatter(stdout, '\t');
    for (GroupInfo info : listGroups.get()) {
        formatter.addColumn(MoreObjects.firstNonNull(info.name, "n/a"));
        if (verboseOutput) {
            Optional<InternalGroup> group = info.ownerId != null ? groupCache.get(AccountGroup.uuid(Url.decode(info.ownerId))) : Optional.empty();
            formatter.addColumn(Url.decode(info.id));
            formatter.addColumn(Strings.nullToEmpty(info.description));
            formatter.addColumn(group.map(InternalGroup::getName).orElse("n/a"));
            formatter.addColumn(group.map(g -> g.getGroupUUID().get()).orElse(""));
            formatter.addColumn(Boolean.toString(MoreObjects.firstNonNull(info.options.visibleToAll, Boolean.FALSE)));
        }
        formatter.nextLine();
    }
    formatter.finish();
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ColumnFormatter(com.google.gerrit.server.ioutil.ColumnFormatter) InternalGroup(com.google.gerrit.entities.InternalGroup)

Aggregations

InternalGroup (com.google.gerrit.entities.InternalGroup)1 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)1 ColumnFormatter (com.google.gerrit.server.ioutil.ColumnFormatter)1