aboutsummaryrefslogtreecommitdiffstats
path: root/main/augeas/0015-Shellvars-support-pipes-in-commands.patch
blob: ec51ebc0cf7fd13576eef994e9847729b75c7429 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
From cb47cc557e19c38f8a6f04ac6f2af2c1a8a1c12a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphael.pinson@camptocamp.com>
Date: Mon, 3 Aug 2015 14:47:13 +0200
Subject: [PATCH 15/19] Shellvars: support pipes in commands

---
 lenses/shellvars.aug            | 12 ++++++++----
 lenses/tests/test_shellvars.aug |  8 ++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index f9e03ff..f68f5bb 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -116,11 +116,18 @@ module Shellvars =
                                             . ( action "&&" "@and" | action "||" "@or" )*
     in Util.indent . label "@condition" . (cond "[" "]" | cond "[[" "]]")
 
-  let command =
+  (* Entry types *)
+  let entry_eol_item (item:lens) = [ item . comment_or_eol ]
+  let entry_item (item:lens) = [ item ]
+
+  (* Command *)
+  let rec command =
        let reserved_key = /exit|shift|return|ulimit|unset|export|source|\.|if|for|select|while|until|then|else|fi|done|case|eval|alias/
     in let word = /[A-Za-z0-9_.-\/]+/
+    in let pipe = del /[ \t]*\|[ \t]*/ " | "
     in Util.indent . label "@command" . store (word - reserved_key)
      . [ Sep.space . label "@arg" . sto_to_semicol]?
+     . (pipe . (entry_eol_item command | entry_item command) )*
 
 (************************************************************************
  * Group:                 CONDITIONALS AND LOOPS
@@ -179,8 +186,6 @@ module Shellvars =
       . Util.indent . Util.del_str "}" . eol ]
 
   let entry_eol =
-    let entry_eol_item (item:lens) =
-      [ item . comment_or_eol ] in
       entry_eol_item source
         | entry_eol_item kv
         | entry_eol_item unset
@@ -193,7 +198,6 @@ module Shellvars =
         | entry_eol_item command
 
   let entry_noeol =
-    let entry_item (item:lens) = [ item ] in
       entry_item source
         | entry_item kv
         | entry_item unset
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index f065ce4..e0bf7fb 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -622,6 +622,14 @@ test Shellvars.lns get "echo foobar 'and this is baz'
     { "@arg" = "with args" }
   }
 
+(* Test: Shellvars.lns
+     Support pipes in commands *)
+test Shellvars.lns get "echo \"$STRING\" | grep foo\n" =
+  { "@command" = "echo"
+    { "@arg" = "\"$STRING\"" }
+    { "@command" = "grep"
+      { "@arg" = "foo" } } }
+
 (* Local Variables: *)
 (* mode: caml       *)
 (* End:             *)
-- 
2.5.0