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/13 23:54:54 UTC

[camel] 03/03: CAMEL-18716: camel-jbang - Extend file path completion to init/bind commands

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 dded47f385f2f7911b458aababd9955fa11607ff
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Sun Nov 13 21:56:29 2022 +0900

    CAMEL-18716: camel-jbang - Extend file path completion to init/bind commands
---
 .../org/apache/camel/dsl/jbang/core/commands/Bind.java  | 15 ++++++++++++++-
 .../org/apache/camel/dsl/jbang/core/commands/Init.java  | 17 +++++++++++++++--
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Bind.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Bind.java
index 6a8fd6bf778..4f8d25739f5 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Bind.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Bind.java
@@ -19,8 +19,10 @@ package org.apache.camel.dsl.jbang.core.commands;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.Iterator;
 import java.util.Set;
+import java.util.Stack;
 
 import org.apache.camel.github.GitHubResourceResolver;
 import org.apache.camel.impl.engine.DefaultResourceResolvers;
@@ -55,7 +57,10 @@ class Bind extends CamelCommand {
                         required = true)
     String sink;
 
-    @CommandLine.Parameters(description = "Name of binding file to be saved", arity = "1")
+    @CommandLine.Parameters(description = "Name of binding file to be saved", arity = "1",
+                            paramLabel = "<file>", parameterConsumer = FileConsumer.class)
+    Path filePath; // Defined only for file path completion; the field never used
+
     String file;
 
     public Bind(CamelJBangMain main) {
@@ -189,4 +194,12 @@ class Bind extends CamelCommand {
         return sb.toString();
     }
 
+    static class FileConsumer extends ParameterConsumer<Bind> {
+        @Override
+        protected void doConsumeParameters(Stack<String> args, Bind cmd) {
+            String arg = args.pop();
+            cmd.file = arg;
+        }
+    }
+
 }
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java
index ad2d5ca3f65..a757762470f 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java
@@ -19,6 +19,8 @@ package org.apache.camel.dsl.jbang.core.commands;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
+import java.nio.file.Path;
+import java.util.Stack;
 import java.util.StringJoiner;
 
 import org.apache.camel.CamelContext;
@@ -31,9 +33,9 @@ import org.apache.camel.spi.Resource;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.IOHelper;
 import org.apache.commons.io.IOUtils;
-import picocli.CommandLine;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Option;
+import picocli.CommandLine.Parameters;
 
 import static org.apache.camel.dsl.jbang.core.common.GistHelper.fetchGistUrls;
 import static org.apache.camel.dsl.jbang.core.common.GitHubHelper.asGithubSingleUrl;
@@ -42,7 +44,10 @@ import static org.apache.camel.dsl.jbang.core.common.GitHubHelper.fetchGithubUrl
 @Command(name = "init", description = "Creates a new Camel integration")
 class Init extends CamelCommand {
 
-    @CommandLine.Parameters(description = "Name of integration file (or a github link)", arity = "1")
+    @Parameters(description = "Name of integration file (or a github link)", arity = "1",
+                paramLabel = "<file>", parameterConsumer = FileConsumer.class)
+    private Path filePath; // Defined only for file path completion; the field never used
+
     private String file;
 
     @Option(names = { "--integration" },
@@ -224,4 +229,12 @@ class Init extends CamelCommand {
         return 0;
     }
 
+    static class FileConsumer extends ParameterConsumer<Init> {
+        @Override
+        protected void doConsumeParameters(Stack<String> args, Init cmd) {
+            String arg = args.pop();
+            cmd.file = arg;
+        }
+    }
+
 }