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/05/17 11:00:33 UTC

[camel-kamelets-examples] 02/02: CAMEL-18118: camel-jbang - Linux terminal scripting using pipes

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-kamelets-examples.git

commit 9e6542e8926499195513f2ca790cc9fe20c246eb
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue May 17 12:34:15 2022 +0200

    CAMEL-18118: camel-jbang - Linux terminal scripting using pipes
---
 jbang/pipe/README.adoc | 19 +++++++------------
 jbang/pipe/upper.yaml  | 10 ++++++++++
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/jbang/pipe/README.adoc b/jbang/pipe/README.adoc
index 684f265..6148a3c 100644
--- a/jbang/pipe/README.adoc
+++ b/jbang/pipe/README.adoc
@@ -1,17 +1,11 @@
 == Pipe
 
 This example shows how to use Camel with terminal scripting.
-The script is coded in Java in the `to_csv.java` file.
 
-The script reads from system:in (using the camel stream component)
-which automatic will split the input line by line. Each line
-is aggregated and assembled into a single comma separated output,
-that is routed to system:out.
-
-Yes this is overkill to use Camel to transform such kind of task,
-but we wanted to keep this example simple, but use EIPs instead
-of a basic from -> to route.
+There are 2 scripts:
 
+- upper.yaml - Upper cases the input
+- to_csv.java - Aggregates the input into a single comma separated output
 
 === Install JBang
 
@@ -26,11 +20,12 @@ $ jbang --version
 
 This will output the version of JBang.
 
-To make the example runnable as a script, you must ensure the file
+To make the example runnable as a script, you must ensure the files
 has execution permission:
 
 [source,sh]
 ----
+chmod +x upper.yaml
 chmod +x to_csv.java
 ----
 
@@ -38,7 +33,7 @@ To run this example you can then run the script:
 
 [source,sh]
 ----
-echo "Hello\nWorld" | ./to_csv.java
+echo "Hello\nWorld" | ./upper.yaml
 ----
 
 You can combine this with more pipes and filters scripting such as.
@@ -46,7 +41,7 @@ For example from a file that has a set of words:
 
 [source,sh]
 ----
-cat words.txt | sort | ./to_csv.java
+cat words.txt | ./upper.yaml | sort | ./to_csv.java
 ----
 
 === Help and contributions
diff --git a/jbang/pipe/upper.yaml b/jbang/pipe/upper.yaml
new file mode 100755
index 0000000..a8c23cf
--- /dev/null
+++ b/jbang/pipe/upper.yaml
@@ -0,0 +1,10 @@
+///usr/bin/env jbang --quiet camel@apache/camel pipe "$0" "$@" ; exit $?
+# camel-k: language=yaml
+
+# Will upper-case the input
+- from:
+    uri: "stream:in"
+    steps:
+      - setBody:
+          simple: "${body.toUpperCase()}"
+      - to: "stream:out"