You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ts...@apache.org on 2022/11/11 06:06:19 UTC

[camel] branch main updated (e96c07ab979 -> 07561e94b7a)

This is an automated email from the ASF dual-hosted git repository.

tsato pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from e96c07ab979 CAMEL-18700: camel-main - Binding to map should support keys with dot if they are in quotes.
     new 65a66914202 CAMEL-18673: camel-jbang - Provide shell completion for camel CLI
     new 07561e94b7a CAMEL-18673: Add section for shell completion to camel-jbang.adoc

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../user-manual/modules/ROOT/pages/camel-jbang.adoc | 16 ++++++++++++++++
 .../camel/dsl/jbang/core/commands/CamelCommand.java |  3 +++
 .../dsl/jbang/core/commands/CamelJBangMain.java     |  3 ++-
 .../commands/{CodeGenerator.java => Complete.java}  | 21 +++++++++++++++++----
 4 files changed, 38 insertions(+), 5 deletions(-)
 copy dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/{CodeGenerator.java => Complete.java} (63%)


[camel] 02/02: CAMEL-18673: Add section for shell completion to camel-jbang.adoc

Posted by ts...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 07561e94b7a52367299e66c813cf49d0429b4d76
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Fri Nov 11 13:01:05 2022 +0900

    CAMEL-18673: Add section for shell completion to camel-jbang.adoc
---
 docs/user-manual/modules/ROOT/pages/camel-jbang.adoc | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index 8f97b020863..79f327b52c2 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -39,6 +39,22 @@ TIP: The first time you run this command, it may cause dependencies to be cached
 
 All the commands support the `--help` and will display the appropriate help if that flag is provided.
 
+=== Enable shell completion
+
+Camel JBang provides shell completion for bash and zsh out of the box. To enable shell completion for Camel JBang, run:
+
+[source,bash]
+----
+source <(camel completion)
+----
+
+To make it permanent, run:
+
+[source,bash]
+----
+echo 'source <(camel completion)' >> ~/.bashrc
+----
+
 == Creating and running Camel routes
 
 You can create a new basic routes with the `init` command.


[camel] 01/02: CAMEL-18673: camel-jbang - Provide shell completion for camel CLI

Posted by ts...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 65a66914202cbc7f9e73cdaa6267744c2e5d7d87
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Fri Nov 11 12:43:41 2022 +0900

    CAMEL-18673: camel-jbang - Provide shell completion for camel CLI
---
 .../dsl/jbang/core/commands/CamelCommand.java      |  3 ++
 .../dsl/jbang/core/commands/CamelJBangMain.java    |  3 +-
 .../camel/dsl/jbang/core/commands/Complete.java    | 46 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java
index 5653768a46b..acc543d0d41 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java
@@ -23,6 +23,9 @@ import picocli.CommandLine;
 
 public abstract class CamelCommand implements Callable<Integer> {
 
+    @CommandLine.Spec
+    CommandLine.Model.CommandSpec spec;
+
     private final CamelJBangMain main;
     private File camelDir;
 
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
index aeb3527cc74..36549b2cad1 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
@@ -115,7 +115,8 @@ public class CamelJBangMain implements Callable<Integer> {
                 .addSubcommand("bind", new CommandLine(new Bind(main)))
                 .addSubcommand("pipe", new CommandLine(new Pipe(main)))
                 .addSubcommand("dependencies", new CommandLine(new DependencyTree(main)))
-                .addSubcommand("export", new CommandLine(new Export(main)));
+                .addSubcommand("export", new CommandLine(new Export(main)))
+                .addSubcommand("completion", new CommandLine(new Complete(main)));
 
         commandLine.getCommandSpec().versionProvider(() -> {
             CamelCatalog catalog = new DefaultCamelCatalog();
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Complete.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Complete.java
new file mode 100644
index 00000000000..e958ff1efa1
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Complete.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands;
+
+import java.io.PrintStream;
+
+import picocli.AutoComplete;
+import picocli.CommandLine;
+
+@CommandLine.Command(name = "complete", description = "Generate completion script for bash/zsh")
+class Complete extends CamelCommand {
+
+    public Complete(CamelJBangMain main) {
+        super(main);
+    }
+
+    @Override
+    public Integer call() throws Exception {
+        String script = AutoComplete.bash(
+                spec.parent().name(),
+                spec.parent().commandLine());
+
+        // not PrintWriter.println: scripts with Windows line separators fail in strange
+        // ways!
+        PrintStream out = System.out;
+        out.print(script);
+        out.print('\n');
+        out.flush();
+        return 0;
+    }
+
+}