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 1b4647897ae camel-jbang - Add doc command
1b4647897ae is described below
commit 1b4647897aefae4a3327857d30330941b47ab069
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Sep 18 10:10:21 2022 +0200
camel-jbang - Add doc command
---
.../modules/ROOT/pages/camel-jbang.adoc | 47 +++++++++++++++++
.../jbang/core/commands/catalog/CatalogDoc.java | 60 +++++++++++++++++++---
2 files changed, 99 insertions(+), 8 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index 0657a697ad8..1ca8bbc667b 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -986,6 +986,53 @@ camel catalog kamelets
TIP: Use `camel catalog --help` to see all possible commands.
+=== Displaying component documentation
+
+The `doc` goal can show quick documentation for every component, dataformat,
kamelets etc.
+For example to see the kafka component you run
+
+[source,bash]
+----
+camel doc kafka
+----
+
+NOTE: The documentation is not the full documentation as shown on the website,
as the Camel CLI does not have direct
+access to this information and can only show a basic description of the
component, but include tables for every
+configuration option.
+
+To see the documentation for jackson dataformat:
+
+[source,bash]
+----
+camel doc jackson
+----
+
+In some rare cases then there may be a component and dataformat with the same
name, and the `doc` goal prioritizes
+components. In such a situation you can prefix the name with dataformat, i.e:
+
+[source,bash]
+----
+camel doc dataformat:thrift
+----
+
+==== Filtering options listed in the tables
+
+Some components may have many options, and in such cases you may use
`--filter` to only list options that match the filter
+in either name, description, or the group (producer, security, advanced etc).
+
+For example to list only security related options:
+
+[source,bash]
+----
+camel doc kafka --filter=security
+----
+
+And to list only something about _timeout_:
+
+[source,bash]
+----
+camel doc kafka --filter=timeout
+----
== Open API
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogDoc.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogDoc.java
index a1d33c8b8a7..2d124c60f56 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogDoc.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/catalog/CatalogDoc.java
@@ -17,6 +17,9 @@
package org.apache.camel.dsl.jbang.core.commands.catalog;
import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
import com.github.freva.asciitable.AsciiTable;
import com.github.freva.asciitable.Column;
@@ -42,6 +45,13 @@ public class CatalogDoc extends CamelCommand {
arity = "1")
String name;
+ @CommandLine.Option(names = { "--filter" },
+ description = "Filter option listed in tables by name,
description, or group")
+ String filter;
+
+ // TODO: kamelet
+ // TODO: endpoint uri to document the uri only
+
final CamelCatalog catalog = new DefaultCamelCatalog(true);
public CatalogDoc(CamelJBangMain main) {
@@ -132,8 +142,15 @@ public class CatalogDoc extends CamelCommand {
.with(r -> r.getShortDefaultValue(40)),
new
Column().header("TYPE").dataAlign(HorizontalAlign.LEFT).with(BaseOptionModel::getShortJavaType))));
System.out.println("");
- System.out.printf("Query parameters (%s):%n",
cm.getEndpointParameterOptions().size());
- System.out.println(AsciiTable.getTable(AsciiTable.FANCY_ASCII,
cm.getEndpointParameterOptions(), Arrays.asList(
+ var filtered = filter(filter, cm.getEndpointParameterOptions());
+ var total1 = cm.getEndpointParameterOptions().size();
+ var total2 = filtered.size();
+ if (total1 == total2) {
+ System.out.printf("Query parameters (total: %s):%n", total1);
+ } else {
+ System.out.printf("Query parameters (total: %s match-filter:
%s):%n", total1, total2);
+ }
+ System.out.println(AsciiTable.getTable(AsciiTable.FANCY_ASCII,
filtered, Arrays.asList(
new
Column().header("NAME").dataAlign(HorizontalAlign.LEFT).minWidth(20).maxWidth(30,
OverflowBehaviour.NEWLINE)
.with(this::getName),
new
Column().header("DESCRIPTION").dataAlign(HorizontalAlign.LEFT).with(this::getDescription),
@@ -159,9 +176,17 @@ public class CatalogDoc extends CamelCommand {
System.out.println(" <version>" + dm.getVersion() +
"</version>");
System.out.println(" </dependency>");
System.out.println("");
- System.out.printf("The %s dataformat supports %s options, which are
listed below.%n%n", dm.getName(),
- dm.getOptions().size());
- System.out.println(AsciiTable.getTable(AsciiTable.FANCY_ASCII,
dm.getOptions(), Arrays.asList(
+ var filtered = filter(filter, dm.getOptions());
+ var total1 = dm.getOptions().size();
+ var total2 = filtered.size();
+ if (total1 == total2) {
+ System.out.printf("The %s dataformat supports (total: %s) options,
which are listed below.%n%n", dm.getName(),
+ total1);
+ } else {
+ System.out.printf("The %s dataformat supports (total: %s
match-filter: %s) options, which are listed below.%n%n",
+ dm.getName(), total1, total2);
+ }
+ System.out.println(AsciiTable.getTable(AsciiTable.FANCY_ASCII,
filtered, Arrays.asList(
new
Column().header("NAME").dataAlign(HorizontalAlign.LEFT).minWidth(20).maxWidth(30,
OverflowBehaviour.NEWLINE)
.with(this::getName),
new
Column().header("DESCRIPTION").dataAlign(HorizontalAlign.LEFT).with(this::getDescription),
@@ -187,9 +212,17 @@ public class CatalogDoc extends CamelCommand {
System.out.println(" <version>" + lm.getVersion() +
"</version>");
System.out.println(" </dependency>");
System.out.println("");
- System.out.printf("The %s language supports %s options, which are
listed below.%n%n", lm.getName(),
- lm.getOptions().size());
- System.out.println(AsciiTable.getTable(AsciiTable.FANCY_ASCII,
lm.getOptions(), Arrays.asList(
+ var filtered = filter(filter, lm.getOptions());
+ var total1 = lm.getOptions().size();
+ var total2 = filtered.size();
+ if (total1 == total2) {
+ System.out.printf("The %s language supports (total: %s) options,
which are listed below.%n%n", lm.getName(),
+ total1);
+ } else {
+ System.out.printf("The %s language supports (total: %s
match-filter: %s) options, which are listed below.%n%n",
+ lm.getName(), total1, total2);
+ }
+ System.out.println(AsciiTable.getTable(AsciiTable.FANCY_ASCII,
filtered, Arrays.asList(
new
Column().header("NAME").dataAlign(HorizontalAlign.LEFT).minWidth(20).maxWidth(30,
OverflowBehaviour.NEWLINE)
.with(this::getName),
new
Column().header("DESCRIPTION").dataAlign(HorizontalAlign.LEFT).with(this::getDescription),
@@ -240,4 +273,15 @@ public class CatalogDoc extends CamelCommand {
return prefix + o.getDescription() + suffix;
}
+ List<? extends BaseOptionModel> filter(String name, List<? extends
BaseOptionModel> options) {
+ if (name == null || name.isEmpty()) {
+ return options;
+ }
+ String target = name.toLowerCase(Locale.ROOT);
+ return options.stream().filter(
+ r -> r.getName().equalsIgnoreCase(target) ||
r.getDescription().toLowerCase(Locale.ROOT).contains(target)
+ || r.getShortGroup() != null &&
r.getShortGroup().toLowerCase(Locale.ROOT).contains(target))
+ .collect(Collectors.toList());
+ }
+
}