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

[camel] 03/05: CAMEL-18743 - camel-jbang - Command to see only if everything is okay or there has been a failure

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

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

commit 8fe67d3c952526802a0029a89c687f0fed90e366
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Dec 6 11:29:16 2022 +0100

    CAMEL-18743 - camel-jbang - Command to see only if everything is okay or there has been a failure
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../jbang/core/commands/process/CamelCount.java    | 51 ++++++++++++++++++----
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelCount.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelCount.java
index 54066cb5931..d941e2fde1f 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelCount.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelCount.java
@@ -43,6 +43,14 @@ public class CamelCount extends ProcessBaseCommand {
                         description = "Sort by pid, name or age", defaultValue = "pid")
     String sort;
 
+    @CommandLine.Option(names = { "--total" },
+            description = "Get the total exchanges from a running integration")
+    boolean total;
+
+    @CommandLine.Option(names = { "--fail" },
+            description = "Get the failed exchanges from a running integration")
+    boolean fail;
+
     public CamelCount(CamelJBangMain main) {
         super(main);
     }
@@ -81,14 +89,41 @@ public class CamelCount extends ProcessBaseCommand {
         // sort rows
         rows.sort(this::sortRow);
 
-        if (!rows.isEmpty()) {
-            System.out.println(AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList(
-                    new Column().header("PID").headerAlign(HorizontalAlign.CENTER).with(r -> r.pid),
-                    new Column().header("NAME").dataAlign(HorizontalAlign.LEFT).maxWidth(30, OverflowBehaviour.ELLIPSIS_RIGHT)
-                            .with(r -> r.name),
-                    new Column().header("AGE").headerAlign(HorizontalAlign.CENTER).with(r -> r.age),
-                    new Column().header("TOTAL").with(r -> r.total),
-                    new Column().header("FAIL").with(r -> r.failed))));
+        if (!total && !fail) {
+            if (!rows.isEmpty()) {
+                System.out.println(AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList(
+                        new Column().header("PID").headerAlign(HorizontalAlign.CENTER).with(r -> r.pid),
+                        new Column().header("NAME").dataAlign(HorizontalAlign.LEFT).maxWidth(30, OverflowBehaviour.ELLIPSIS_RIGHT)
+                                .with(r -> r.name),
+                        new Column().header("AGE").headerAlign(HorizontalAlign.CENTER).with(r -> r.age),
+                        new Column().header("TOTAL").with(r -> r.total),
+                        new Column().header("FAIL").with(r -> r.failed))));
+            }
+        } else {
+            StringBuilder builder = new StringBuilder();
+            if (total || fail) {
+                if (!rows.isEmpty()) {
+                    int index = 0;
+                    for (Row r: rows
+                         ) {
+                        if (rows.size() > 1) {
+                            builder.append(r.name).append(",");
+                        }
+                        if (total) {
+                            builder.append(r.total);
+                        }
+                        if (fail) {
+                            if (total) builder.append(",");
+                            builder.append(r.failed);
+                        }
+                        if (index < rows.size()-1) {
+                            builder.append(System.getProperty("line.separator"));
+                        }
+                        index++;
+                    }
+                }
+            }
+            System.out.println(builder.toString());
         }
 
         return 0;