Search in sources :

Example 46 with Table

use of co.cask.cdap.cli.util.table.Table in project cdap by caskdata.

the class ListAppsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String artifactNamesStr = arguments.getOptional(ArgumentName.ARTIFACT_NAME.toString());
    String artifactVersion = arguments.getOptional(ArgumentName.ARTIFACT_VERSION.toString());
    Set<String> artifactNames = new HashSet<>();
    if (artifactNamesStr != null) {
        for (String name : Splitter.on(',').trimResults().split(artifactNamesStr)) {
            artifactNames.add(name);
        }
    }
    Table table = Table.builder().setHeader("id", "appVersion", "description", "artifactName", "artifactVersion", "artifactScope", "principal").setRows(appClient.list(cliConfig.getCurrentNamespace(), artifactNames, artifactVersion), new RowMaker<ApplicationRecord>() {

        @Override
        public List<?> makeRow(ApplicationRecord object) {
            return Lists.newArrayList(object.getName(), object.getAppVersion(), object.getDescription(), object.getArtifact().getName(), object.getArtifact().getVersion(), object.getArtifact().getScope(), object.getOwnerPrincipal());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) HashSet(java.util.HashSet) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 47 with Table

use of co.cask.cdap.cli.util.table.Table in project cdap by caskdata.

the class ListArtifactPluginsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
    String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
    ArtifactId artifactId = cliConfig.getCurrentNamespace().artifact(artifactName, artifactVersion);
    String pluginType = arguments.get(ArgumentName.PLUGIN_TYPE.toString());
    final List<PluginSummary> pluginSummaries;
    String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
    if (scopeStr == null) {
        pluginSummaries = artifactClient.getPluginSummaries(artifactId, pluginType);
    } else {
        pluginSummaries = artifactClient.getPluginSummaries(artifactId, pluginType, ArtifactScope.valueOf(scopeStr.toUpperCase()));
    }
    Table table = Table.builder().setHeader("type", "name", "classname", "description", "artifact").setRows(pluginSummaries, new RowMaker<PluginSummary>() {

        @Override
        public List<?> makeRow(PluginSummary object) {
            return Lists.newArrayList(object.getType(), object.getName(), object.getClassName(), object.getDescription(), object.getArtifact().toString());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) ArtifactId(co.cask.cdap.proto.id.ArtifactId) RowMaker(co.cask.cdap.cli.util.RowMaker) PluginSummary(co.cask.cdap.proto.artifact.PluginSummary)

Example 48 with Table

use of co.cask.cdap.cli.util.table.Table in project cdap by caskdata.

the class CLIMainTest method testNamespacesOutput.

private static void testNamespacesOutput(CLI cli, String command, final List<NamespaceMeta> expected) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintStream output = new PrintStream(outputStream);
    Table table = Table.builder().setHeader("name", "description", "config").setRows(expected, new RowMaker<NamespaceMeta>() {

        @Override
        public List<?> makeRow(NamespaceMeta object) {
            return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
        }
    }).build();
    cliMain.getTableRenderer().render(cliConfig, output, table);
    final String expectedOutput = outputStream.toString();
    testCommand(cli, command, new Function<String, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable String output) {
            Assert.assertNotNull(output);
            Assert.assertEquals(expectedOutput, output);
            return null;
        }
    });
}
Also used : PrintStream(java.io.PrintStream) Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Nullable(javax.annotation.Nullable)

Aggregations

Table (co.cask.cdap.cli.util.table.Table)48 RowMaker (co.cask.cdap.cli.util.RowMaker)38 CommandInputError (co.cask.cdap.cli.exception.CommandInputError)7 List (java.util.List)7 ArtifactId (co.cask.cdap.proto.id.ArtifactId)5 StreamId (co.cask.cdap.proto.id.StreamId)5 Nullable (javax.annotation.Nullable)5 ArtifactScope (co.cask.cdap.api.artifact.ArtifactScope)3 DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)3 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)3 ProgramRecord (co.cask.cdap.proto.ProgramRecord)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3 DatasetId (co.cask.cdap.proto.id.DatasetId)3 EntityId (co.cask.cdap.proto.id.EntityId)3 ProgramId (co.cask.cdap.proto.id.ProgramId)3 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)3 Map (java.util.Map)3 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)2 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)2 BatchProgramResult (co.cask.cdap.proto.BatchProgramResult)2