This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 3b3d01054bc Implements CAMEL-19044 (#9356) 3b3d01054bc is described below commit 3b3d01054bc8e630ceb94f846e20cb05c7211690 Author: Marat Gubaidullin <marat.gubaidul...@gmail.com> AuthorDate: Wed Feb 15 12:24:45 2023 -0500 Implements CAMEL-19044 (#9356) * Implements CAMEL-19044 * Replace Vert.x JSON library to camel-util-json --- .../core/commands/catalog/CatalogBaseCommand.java | 32 ++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogBaseCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogBaseCommand.java index d8d735a81e2..7322dad8934 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogBaseCommand.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogBaseCommand.java @@ -19,6 +19,7 @@ package org.apache.camel.dsl.jbang.core.commands.catalog; import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.stream.Collectors; import com.github.freva.asciitable.AsciiTable; @@ -33,6 +34,7 @@ import org.apache.camel.dsl.jbang.core.common.RuntimeUtil; import org.apache.camel.dsl.jbang.core.common.VersionHelper; import org.apache.camel.main.download.MavenGav; import org.apache.camel.tooling.model.ArtifactModel; +import org.apache.camel.util.json.Jsoner; import picocli.CommandLine; public abstract class CatalogBaseCommand extends CamelCommand { @@ -72,6 +74,10 @@ public abstract class CatalogBaseCommand extends CamelCommand { description = "Filter by version more recent (inclusive)") String sinceAfter; + @CommandLine.Option(names = { "--json" }, + description = "Output in JSON Format") + boolean jsonOutput; + CamelCatalog catalog; public CatalogBaseCommand(CamelJBangMain main) { @@ -129,14 +135,24 @@ public abstract class CatalogBaseCommand extends CamelCommand { rows.sort(this::sortRow); if (!rows.isEmpty()) { - System.out.println(AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList( - new Column().header("NAME").visible(!gav).dataAlign(HorizontalAlign.LEFT).maxWidth(30).with(r -> r.name), - new Column().header("ARTIFACT-ID").visible(gav).dataAlign(HorizontalAlign.LEFT).with(this::shortGav), - new Column().header("LEVEL").dataAlign(HorizontalAlign.LEFT).with(r -> r.level), - new Column().header("NATIVE").dataAlign(HorizontalAlign.CENTER) - .visible("quarkus".equals(runtime)).with(this::nativeSupported), - new Column().header("SINCE").dataAlign(HorizontalAlign.RIGHT).with(r -> r.since), - new Column().header("DESCRIPTION").dataAlign(HorizontalAlign.LEFT).with(this::shortDescription)))); + if (jsonOutput) { + System.out.println( + Jsoner.serialize( + rows.stream().map(row -> Map.of( + "name", row.name, + "level", row.level, + "native", row.nativeSupported)).collect(Collectors.toList()))); + } else { + System.out.println(AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList( + new Column().header("NAME").visible(!gav).dataAlign(HorizontalAlign.LEFT).maxWidth(30) + .with(r -> r.name), + new Column().header("ARTIFACT-ID").visible(gav).dataAlign(HorizontalAlign.LEFT).with(this::shortGav), + new Column().header("LEVEL").dataAlign(HorizontalAlign.LEFT).with(r -> r.level), + new Column().header("NATIVE").dataAlign(HorizontalAlign.CENTER) + .visible("quarkus".equals(runtime)).with(this::nativeSupported), + new Column().header("SINCE").dataAlign(HorizontalAlign.RIGHT).with(r -> r.since), + new Column().header("DESCRIPTION").dataAlign(HorizontalAlign.LEFT).with(this::shortDescription)))); + } } return 0;