You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/18 20:40:04 UTC

[camel] branch main updated: CAMEL-18389: camel-jbang - camel stop to stop running Camel

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 405a2809f00 CAMEL-18389: camel-jbang - camel stop to stop running Camel
405a2809f00 is described below

commit 405a2809f00c7c7b2c370c9927fd63c0af0edda3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 18 22:39:51 2022 +0200

    CAMEL-18389: camel-jbang - camel stop to stop running Camel
---
 docs/user-manual/modules/ROOT/pages/camel-jbang.adoc | 12 ++++++++++++
 .../camel/dsl/jbang/core/commands/StopProcess.java   | 20 +++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index f7fa070afa4..bb8f1f4c136 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -548,6 +548,18 @@ camel stop 44805
 Stopping running Camel integration (pid: 44805)
 ----
 
+TIP: You do not have to type the full name, as the stop command will match using integrations
+that starts with the input, for example you can do `camel stop d` to stop all integrations
+starting with d.
+
+To stop all integrations then you need to use the `--all` option as follows:
+
+[source,bash]
+----
+camel stop --all
+Stopping running Camel integration (pid: 42171)
+Stopping running Camel integration (pid: 44805)
+----
 
 === Scripting from terminal using pipes
 
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/StopProcess.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/StopProcess.java
index d3d1f4a23c3..e35eaf97a04 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/StopProcess.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/StopProcess.java
@@ -29,20 +29,34 @@ import picocli.CommandLine.Command;
 @Command(name = "stop", description = "Stop a running Camel integration")
 class StopProcess extends CamelCommand {
 
-    @CommandLine.Parameters(description = "Name or pid of running Camel integration", arity = "1")
+    @CommandLine.Parameters(description = "Name or pid of running Camel integration", arity = "0..1")
     private String name;
 
+    @CommandLine.Option(names = { "--all" },
+                        description = "To stop all running Camel integrations")
+    private boolean all;
+
     public StopProcess(CamelJBangMain main) {
         super(main);
     }
 
     @Override
     public Integer call() throws Exception {
+        if (!all && name == null) {
+            return 0;
+        } else if (all) {
+            name = "*";
+        }
+
         // we need to know the pids of the running camel integrations
         List<Long> pids;
         if (name.matches("\\d+")) {
             pids = List.of(Long.parseLong(name));
         } else {
+            // lets be open and match all that starts with this pattern
+            if (!name.endsWith("*")) {
+                name = name + "*";
+            }
             pids = findPids(name);
         }
 
@@ -74,9 +88,9 @@ class StopProcess extends CamelCommand {
         ProcessHandle.allProcesses()
                 .forEach(ph -> {
                     String name = extractName(ph);
-                    // ignore file extension so it is easier to match by name
+                    // ignore file extension, so it is easier to match by name
                     name = FileUtil.onlyName(name);
-                    if (PatternHelper.matchPattern(name, pattern)) {
+                    if (!name.isEmpty() && PatternHelper.matchPattern(name, pattern)) {
                         pids.add(ph.pid());
                     }
                 });