This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.x by this push:
new 1915afea6da Implements CAMEL-19044 (#9355)
1915afea6da is described below
commit 1915afea6dacef66b2e1361cffa43e3a52f23381
Author: Marat Gubaidullin <[email protected]>
AuthorDate: Wed Feb 15 12:24:23 2023 -0500
Implements CAMEL-19044 (#9355)
* 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;