[camel] branch main updated: CAMEL-18388: camel-jbang - add directory option to init to save to this folder

2022-08-13 Thread davsclaus
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 0338b342349 CAMEL-18388: camel-jbang - add directory option to init to 
save to this folder
0338b342349 is described below

commit 0338b3423495e3049628fd96c3c017f2b6afebfd
Author: Claus Ibsen 
AuthorDate: Sat Aug 13 10:28:09 2022 +0200

CAMEL-18388: camel-jbang - add directory option to init to save to this 
folder
---
 .../modules/ROOT/pages/camel-jbang.adoc| 37 --
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index b85179421df..da896f15d95 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -50,7 +50,7 @@ For example to create an XML route you do:
 camel init cheese.xml
 
 
-Which creates the file `cheese.xml` with a sample route.
+Which creates the file `cheese.xml` (in the current directory) with a sample 
route.
 
 To run the file, you simply do:
 
@@ -68,6 +68,17 @@ To create a new .java route, you simply do:
 camel init foo.java
 
 
+When using the init command then Camel will by default create the file in the 
current directory. However, you can use
+the `--directory` option to create the file in the specified directory. For 
example to create in a folder
+named _foobar_ you can do:
+
+[source,bash]
+
+camel init foo.java --directory=foobar
+
+
+IMPORTANT: When using `--directory` then Camel will automatically clean this 
directory if already exists.
+
 === Running Routes from multiple files
 
 You can run more than 1 file, for example to run two YAML files you can do:
@@ -105,7 +116,7 @@ And to run everything
 camel run *
 
 
-TIP: The run goal can also detect files that are `properties`.
+TIP: The run goal can also detect files that are `properties`, such as 
`application.properties`.
 
 === Dev mode with live reload
 
@@ -363,6 +374,16 @@ The example can then be run locally with:
 camel run *
 
 
+You can also download to a new folder using the `--directory` option, for 
example to download to a folder named _myproject_,
+you would do:
+
+[source,bash]
+
+camel init 
https://github.com/apache/camel-kamelets-examples/tree/main/jbang/dependency-injection
 --directory=myproject
+
+
+IMPORTANT: When using `--directory` then Camel will automatically clean this 
directory if already exists.
+
 You can also run in dev mode, to hot-deploy on source code changes.
 
 [source,bash]
@@ -400,6 +421,17 @@ This will then download the files to local disk, which you 
can run afterwards:
 camel run *
 
 
+You can also download to a new folder using the `--directory` option, for 
example to download to a folder named _foobar_,
+you would do:
+
+[source,bash]
+
+camel init https://gist.github.com/davsclaus/477ddff5cdeb1ae03619aa544ce47e92 
--directory=foobar
+
+
+IMPORTANT: When using `--directory` then Camel will automatically clean this 
directory if already exists.
+
+
 === Using a specific Camel version
 
 You can specify which Camel version to run as shown:
@@ -416,6 +448,7 @@ And you can also try bleeding edge development by using 
SNAPSHOT such as:
 jbang run -Dcamel.jbang.version=3.19.0-SNAPSHOT camel@apache/camel [command]
 
 
+
 === Running Camel K integrations or bindings
 
 Camel also supports running Camel K integrations and binding files, which are 
in CRD format (Kubernetes Custom Resource Definitions).



[camel] branch main updated: CAMEL-18388: camel-jbang - add directory option to init to save to this folder

2022-08-13 Thread davsclaus
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 964bbbee69c CAMEL-18388: camel-jbang - add directory option to init to 
save to this folder
964bbbee69c is described below

commit 964bbbee69cda631def5f1ac432e5f786db9ef0f
Author: Claus Ibsen 
AuthorDate: Sat Aug 13 10:09:25 2022 +0200

CAMEL-18388: camel-jbang - add directory option to init to save to this 
folder
---
 .../dsl/jbang/core/commands/CommandHelper.java | 41 +
 .../dsl/jbang/core/commands/ExportQuarkus.java | 12 +-
 .../apache/camel/dsl/jbang/core/commands/Init.java | 43 ++
 3 files changed, 78 insertions(+), 18 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CommandHelper.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CommandHelper.java
new file mode 100644
index 000..1ce40f1a4f8
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CommandHelper.java
@@ -0,0 +1,41 @@
+/*
+ * 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.File;
+
+import org.apache.camel.util.FileUtil;
+
+public final class CommandHelper {
+
+private CommandHelper() {
+}
+
+public static void cleanExportDir(String dir) {
+File target = new File(dir);
+File[] files = target.listFiles();
+if (files != null) {
+for (File f : files) {
+if (!f.isHidden() && f.isDirectory()) {
+FileUtil.removeDir(f);
+} else if (!f.isHidden() && f.isFile()) {
+FileUtil.deleteFile(f);
+}
+}
+}
+}
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java
index 025e6e706f2..d0df64322e7 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportQuarkus.java
@@ -113,16 +113,8 @@ class ExportQuarkus extends Export {
 copyMavenWrapper();
 }
 
-if (exportDir.equals(".")) {
-// we export to current dir so prepare for this by cleaning up 
existing files
-File target = new File(exportDir);
-for (File f : target.listFiles()) {
-if (!f.isHidden() && f.isDirectory()) {
-FileUtil.removeDir(f);
-} else if (!f.isHidden() && f.isFile()) {
-f.delete();
-}
-}
+if (!exportDir.equals(".")) {
+CommandHelper.cleanExportDir(exportDir);
 }
 // copy to export dir and remove work dir
 FileUtils.copyDirectory(new File(BUILD_DIR), new File(exportDir));
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 c002c9db9c4..17d4313445a 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
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.dsl.jbang.core.commands;
 
+import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.util.StringJoiner;
@@ -40,13 +41,18 @@ import static 
org.apache.camel.dsl.jbang.core.common.GitHubHelper.fetchGithubUrl
 @Command(name = "init", description = "Initialize empty Camel integration")
 class Init extends CamelCommand {
 
-@CommandLine.Parameters(description = "Name of integration file", arity = 
"1")