Commit 01cf06a6 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

main/augeas: align patch set with upstream

01-16: committed to upstream
17: GH #331
18: GH #332
19: GH #333
parent 6ef17280
From 37a817680eb162a21fa6e2eac8feda5973dfb465 Mon Sep 17 00:00:00 2001
From 239ee5f55eaae79362476cecaaf6c5064cb323b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphael.pinson@camptocamp.com>
Date: Mon, 13 Jul 2015 10:03:21 +0200
Subject: [PATCH 01/15] Shellvars: accept [] and [[]] builtins
Subject: [PATCH 01/19] Shellvars: accept [] and [[]] builtins
Fix GH #188
---
......@@ -60,5 +60,5 @@ index 7a89f11..778a8d2 100644
(* mode: caml *)
(* End: *)
--
2.1.0
2.5.0
From e038a40dc8c7c4e2121ce40fc493c26f8cfcc46f Mon Sep 17 00:00:00 2001
From 468fbf6dfe9ab48e4861a5dfa799a7170bea5c08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphael.pinson@camptocamp.com>
Date: Mon, 13 Jul 2015 10:04:38 +0200
Subject: [PATCH 02/15] Shellvars: Add test for [[]]
Subject: [PATCH 02/19] Shellvars: Add test for [[]]
---
lenses/tests/test_shellvars.aug | 4 ++++
......@@ -23,5 +23,5 @@ index 778a8d2..a2d4f28 100644
(* mode: caml *)
(* End: *)
--
2.1.0
2.5.0
From a70c92f52136398ffbe6e5fd70effd3984e84a5f Mon Sep 17 00:00:00 2001
From ad5777d3bef4dcd74a2dcd09d4679b034ba16180 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Thu, 4 Dec 2014 14:31:26 +0200
Subject: [PATCH 03/15] Shellvars: allow partial quoting, mixing multiple
Subject: [PATCH 03/19] Shellvars: allow partial quoting, mixing multiple
styles
---
......@@ -65,5 +65,5 @@ index a2d4f28..864cb6c 100644
test Shellvars.lns get "unset ${!LC_*}\n" =
{ "@unset"
--
2.1.0
2.5.0
From 672e60257aeaf8471d7b3f0e77c48752aeeccec9 Mon Sep 17 00:00:00 2001
From 1db574636b5bdaecfb3218a0853e3d7c34d724c6 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 8 Dec 2014 13:16:14 +0200
Subject: [PATCH 04/15] Shellvars: allow wrapping loop condition to multiple
Subject: [PATCH 04/19] Shellvars: allow wrapping loop condition to multiple
lines
---
......@@ -38,5 +38,5 @@ index 864cb6c..065130a 100644
(* mode: caml *)
(* End: *)
--
2.1.0
2.5.0
From e86155aec47840e7cce29a6dbaac5bd21f8d9e3a Mon Sep 17 00:00:00 2001
From 23e3316a5539b2a19efe6d497ffcd3906fed1aaf Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 8 Dec 2014 12:43:51 +0200
Subject: [PATCH 05/15] Shellvars: guard against comments
Subject: [PATCH 05/19] Shellvars: guard against comments
---
lenses/shellvars.aug | 2 +-
......@@ -21,5 +21,5 @@ index c767067..78b1d16 100644
let char = /[^"\\]|\\\\./ | Rx.cl
in "\"" . char* . "\"" (* " Emacs, relax *)
--
2.1.0
2.5.0
From 0ab8ce1daeadc690b9b1a195474b21e3c4e9c851 Mon Sep 17 00:00:00 2001
From c39d0c16a8cf540816df94b28f428e3ef3ce2579 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Thu, 4 Dec 2014 18:25:12 +0200
Subject: [PATCH 06/15] Shellvars: allow wrapping builtin arguments to multiple
Subject: [PATCH 06/19] Shellvars: allow wrapping builtin arguments to multiple
lines
---
......@@ -41,5 +41,5 @@ index 065130a..bf92735 100644
test lns get "VAR1=\"this;is;a;test\"\nVAR2=this;\n" =
{ "VAR1" = "\"this;is;a;test\"" }
--
2.1.0
2.5.0
From 25007fa071f37998016b4f197bf6509e43174517 Mon Sep 17 00:00:00 2001
From 7d655518acb7a4c255a40a025621cd73053acce4 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 8 Dec 2014 14:28:16 +0200
Subject: [PATCH 07/15] Shellvars: allow quotes in loop conditions
Subject: [PATCH 07/19] Shellvars: allow quotes in loop conditions
---
lenses/shellvars.aug | 8 +-------
......@@ -50,5 +50,5 @@ index bf92735..6b2210e 100644
(* mode: caml *)
(* End: *)
--
2.1.0
2.5.0
From 2468b3af35eefd019b6cb75836a6fb274cfc20bc Mon Sep 17 00:00:00 2001
From b293b7f30e46ca75127fab698a6ed86523746db3 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 8 Dec 2014 15:17:46 +0200
Subject: [PATCH 08/15] Shellvars: case: support quotes and spaces in pattern
Subject: [PATCH 08/19] Shellvars: case: support quotes and spaces in pattern
lists
---
......@@ -52,5 +52,5 @@ index 6b2210e..9484754 100644
(* mode: caml *)
(* End: *)
--
2.1.0
2.5.0
From c0ceda2cbc93add3392e87a488947691a886af78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphael.pinson@camptocamp.com>
Date: Thu, 30 Jul 2015 09:16:12 +0200
Subject: [PATCH 09/19] Shellvars: add eval builtin support
---
lenses/shellvars.aug | 6 ++++++
lenses/tests/test_shellvars.aug | 4 ++++
2 files changed, 10 insertions(+)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index dc6d4f3..8735d77 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -83,6 +83,10 @@ module Shellvars =
let shell_builtin_cmds = "ulimit" | "shift" | "exit"
+ let eval =
+ Util.indent . Util.del_str "eval" . Util.del_ws_spc
+ . label "@eval" . store anyquot
+
let builtin =
Util.indent . label "@builtin"
. store shell_builtin_cmds
@@ -169,6 +173,7 @@ module Shellvars =
| entry_eol_item builtin
| entry_eol_item return
| entry_eol_item condition
+ | entry_eol_item eval
let entry_noeol =
let entry_item (item:lens) = [ item ] in
@@ -179,6 +184,7 @@ module Shellvars =
| entry_item builtin
| entry_item return
| entry_item condition
+ | entry_item eval
let rec rec_entry =
let entry = comment | entry_eol | rec_entry in
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index 9484754..9d301af 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -580,6 +580,10 @@ esac\n" =
}
}
+ (* eval *)
+ test lns get "eval `dircolors`\n" =
+ { "@eval" = "`dircolors`" }
+
(* Local Variables: *)
(* mode: caml *)
(* End: *)
--
2.5.0
From 2717b7ecb107f5c4bfd9b04eb8543a365500421d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphael.pinson@camptocamp.com>
Date: Thu, 30 Jul 2015 09:22:22 +0200
Subject: [PATCH 10/19] Shellvars: add alias builtin support
---
lenses/shellvars.aug | 7 +++++++
lenses/tests/test_shellvars.aug | 4 ++++
2 files changed, 11 insertions(+)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index 8735d77..f681fcd 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -87,6 +87,11 @@ module Shellvars =
Util.indent . Util.del_str "eval" . Util.del_ws_spc
. label "@eval" . store anyquot
+ let alias =
+ Util.indent . Util.del_str "alias" . Util.del_ws_spc
+ . label "@alias" . store key_re . eq
+ . [ label "value" . store anyquot ]
+
let builtin =
Util.indent . label "@builtin"
. store shell_builtin_cmds
@@ -174,6 +179,7 @@ module Shellvars =
| entry_eol_item return
| entry_eol_item condition
| entry_eol_item eval
+ | entry_eol_item alias
let entry_noeol =
let entry_item (item:lens) = [ item ] in
@@ -185,6 +191,7 @@ module Shellvars =
| entry_item return
| entry_item condition
| entry_item eval
+ | entry_item alias
let rec rec_entry =
let entry = comment | entry_eol | rec_entry in
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index 9d301af..26aec25 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -584,6 +584,10 @@ esac\n" =
test lns get "eval `dircolors`\n" =
{ "@eval" = "`dircolors`" }
+ (* alias *)
+ test lns get "alias ls='ls $LS_OPTIONS'\n" =
+ { "@alias" = "ls" { "value" = "'ls $LS_OPTIONS'" } }
+
(* Local Variables: *)
(* mode: caml *)
(* End: *)
--
2.5.0
From f967f4c6c86a9fff523363d228e8703cfcb2c70e Mon Sep 17 00:00:00 2001
From 60a542a54819deee9a869815df40f99a4391a8fa Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 13 Jul 2015 14:43:09 +0300
Subject: [PATCH 09/15] Shellvars: pattern nodes in case entries
Subject: [PATCH 11/19] Shellvars: pattern nodes in case entries
Breaking change: case entry values are now in a @pattern subnode.
---
lenses/shellvars.aug | 10 +++++----
lenses/tests/test_shellvars.aug | 48 +++++++++++++++++++++++++++--------------
2 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index dc6d4f3..aab9d50 100644
index f681fcd..ed9cc9c 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -34,12 +34,12 @@ module Shellvars =
......@@ -27,7 +28,7 @@ index dc6d4f3..aab9d50 100644
(* dbquot don't take spaces or semi-colons *)
let dbquot = /``[^` \t\n;]+``/
let dollar_assign = /\$\([^\(\)#\n]*\)/
@@ -139,8 +139,10 @@ module Shellvars =
@@ -148,8 +148,10 @@ module Shellvars =
generic_cond "select" "@select" "do" entry+ "done"
let case (entry:lens) (entry_noeol:lens) =
......@@ -41,7 +42,7 @@ index dc6d4f3..aab9d50 100644
. entry* . entry_noeol?
. Util.indent . Util.del_str ";;" . eol ] in
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index 9484754..a397431 100644
index 26aec25..d07918d 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -261,11 +261,14 @@ done\n" =
......@@ -168,5 +169,5 @@ index 9484754..a397431 100644
}
}
--
2.1.0
2.5.0
From 5a3d3528b63986a91baedaca028c646b796961d8 Mon Sep 17 00:00:00 2001
From c6e1f01214b89bb17315704d08f285401abec0db Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 13 Jul 2015 14:48:18 +0300
Subject: [PATCH 10/15] Shellvars: use sto_to_semicol in condition lens
Subject: [PATCH 12/19] Shellvars: use sto_to_semicol in condition lens
---
lenses/shellvars.aug | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index aab9d50..bb0e875 100644
index ed9cc9c..0384a6f 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -98,9 +98,8 @@ module Shellvars =
@@ -107,9 +107,8 @@ module Shellvars =
. ( Util.del_ws_spc . store Rx.integer )?
let condition =
......@@ -24,5 +24,5 @@ index aab9d50..bb0e875 100644
in Util.indent . label "@condition" . (cond "[" "]" | cond "[[" "]]")
--
2.1.0
2.5.0
From 7bad1f085369de5544f8b06e7e0704d7030c3506 Mon Sep 17 00:00:00 2001
From 3db2b565125c3e00914f6def30510aaa71b7d908 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 13 Jul 2015 14:51:37 +0300
Subject: [PATCH 11/15] Shellvars: allow && and || constructs after condition
Subject: [PATCH 13/19] Shellvars: allow && and || constructs after condition
---
lenses/shellvars.aug | 8 ++++++--
......@@ -9,7 +9,7 @@ Subject: [PATCH 11/15] Shellvars: allow && and || constructs after condition
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index bb0e875..3fce699 100644
index 0384a6f..c47f566 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -34,7 +34,7 @@ module Shellvars =
......@@ -21,7 +21,7 @@ index bb0e875..3fce699 100644
let dquot =
let char = /[^"\\]|\\\\./ | Rx.cl
in "\"" . char* . "\"" (* " Emacs, relax *)
@@ -98,9 +98,13 @@ module Shellvars =
@@ -107,9 +107,13 @@ module Shellvars =
. ( Util.del_ws_spc . store Rx.integer )?
let condition =
......@@ -37,12 +37,12 @@ index bb0e875..3fce699 100644
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index a397431..ae432fa 100644
index d07918d..0f27a73 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -596,6 +596,14 @@ esac\n" =
}
}
@@ -604,6 +604,14 @@ esac\n" =
test lns get "alias ls='ls $LS_OPTIONS'\n" =
{ "@alias" = "ls" { "value" = "'ls $LS_OPTIONS'" } }
+ (* Allow && and || constructs after condition *)
+ test Shellvars.lns get "[ -f $FILENAME ] && do this || or that\n" =
......@@ -56,5 +56,5 @@ index a397431..ae432fa 100644
(* mode: caml *)
(* End: *)
--
2.1.0
2.5.0
From 9d896f124404865e996042de74347644a2dd2e3a Mon Sep 17 00:00:00 2001
From ba95bf402b009f0a572807b62ea2a7addd29dc17 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphink@gmail.com>
Date: Thu, 24 Apr 2014 16:10:50 +0200
Subject: [PATCH 12/15] Shellvars: Allow (almost) any command
Subject: [PATCH 14/19] Shellvars: Allow (almost) any command
Note: this may have edge effects in recursive sublenses
that augparse cannot check.
Conflicts:
lenses/shellvars.aug
---
NEWS | 1 +
lenses/shellvars.aug | 7 +++++++
lenses/tests/test_shellvars.aug | 11 +++++++++++
3 files changed, 19 insertions(+)
lenses/tests/test_shellvars.aug | 12 +++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index a748343..3866a92 100644
--- a/NEWS
+++ b/NEWS
@@ -134,6 +134,7 @@
conditions (GH issue #118)
Support $(( .. )) arithmetic expansion in variable
assignment, RHBZ#1100550
+ Allow (almost) any command
* Simplevars: Support flags and empty values
* Sshd: Allow all types of entries in Match groups (GH issue #75)
* Sssd: Allow ; for comments
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index 3fce699..36a0141 100644
index c47f566..f9e03ff 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -107,6 +107,11 @@ module Shellvars =
@@ -116,6 +116,11 @@ module Shellvars =
. ( action "&&" "@and" | action "||" "@or" )*
in Util.indent . label "@condition" . (cond "[" "]" | cond "[[" "]]")
+ let command =
+ let reserved_key = /exit|shift|return|ulimit|unset|export|source|\.|if|for|select|while|until|then|else|fi|done|case/
+ 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 Util.indent . label "@command" . store (word - reserved_key)
+ . [ Sep.space . label "@arg" . sto_to_semicol]?
(************************************************************************
* Group: CONDITIONALS AND LOOPS
@@ -174,6 +179,7 @@ module Shellvars =
| entry_eol_item builtin
| entry_eol_item return
@@ -185,6 +190,7 @@ module Shellvars =
| entry_eol_item condition
| entry_eol_item eval
| entry_eol_item alias
+ | entry_eol_item command
let entry_noeol =
let entry_item (item:lens) = [ item ] in
@@ -184,6 +190,7 @@ module Shellvars =
| entry_item builtin
| entry_item return
@@ -197,6 +203,7 @@ module Shellvars =
| entry_item condition
| entry_item eval
| entry_item alias
+ | entry_item command
let rec rec_entry =
let entry = comment | entry_eol | rec_entry in
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index ae432fa..76f6f59 100644
index 0f27a73..f065ce4 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -604,6 +604,17 @@ esac\n" =
{ "@or" = "or that" }
}
@@ -609,7 +609,17 @@ esac\n" =
{ "@condition" = "-f $FILENAME"
{ "type" = "[" }
{ "@and" = "do this" }
- { "@or" = "or that" }
+ { "@or" = "or that" } }
+
+(* Test: Shellvars.lns
+ Parse (almost) any command *)
+test Shellvars.lns get "echo foobar 'and this is baz'
......@@ -75,11 +62,9 @@ index ae432fa..76f6f59 100644
+ }
+ { "@command" = "/usr/local/bin/myscript.sh"
+ { "@arg" = "with args" }
+ }
+
}
(* Local Variables: *)
(* mode: caml *)
(* End: *)
--
2.1.0
2.5.0
From 70d9a1a8b26957ef5772f634346bccfa1dee8811 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 13 Jul 2015 15:26:04 +0300
Subject: [PATCH 15/15] Shellvars: allow && and || constructs after command
---
lenses/shellvars.aug | 10 +++++++---
lenses/tests/test_shellvars.aug | 8 ++++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index 00c6846..0f7c907 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -97,14 +97,17 @@ module Shellvars =
. Util.del_str "return"
. ( Util.del_ws_spc . store Rx.integer )?
- let condition =
+ let cond_actions=
let action (operator:string) (lbl:string) =
[ Sep.opt_space . Util.del_str operator . Sep.opt_space
. label lbl . sto_to_semicol ]
- in let cond (start:string) (end:string) = [ label "type" . store start ]
+ in ( action "&&" "@and" | action "||" "@or" )*
+
+ let condition =
+ let cond (start:string) (end:string) = [ label "type" . store start ]
. Util.del_ws_spc . sto_to_semicol
. Util.del_ws_spc . Util.del_str end
- . ( action "&&" "@and" | action "||" "@or" )*
+ . cond_actions
in Util.indent . label "@condition" . (cond "[" "]" | cond "[[" "]]")
let command =
@@ -114,6 +117,7 @@ module Shellvars =
. [ key key_re . eq . store anyquot . Sep.space . del /(\\\\\n[ \t]*)?/ "" ]*
. store (word - reserved_key - /zzz/)
. [ Sep.space . label "@arg" . sto_to_semicol]?
+ . cond_actions
(************************************************************************
* Group: CONDITIONALS AND LOOPS
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index 4f52205..00f3aad 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -628,6 +628,14 @@ bar" }
{ "@arg" = "arg1 arg2" }
}
+ (* Allow && and || constructs after command *)
+ test Shellvars.lns get "foo bar && baz || quux\n" =
+ { "@command" = "foo"
+ { "@arg" = "bar" }
+ { "@and" = "baz" }
+ { "@or" = "quux" }
+ }
+
(* Local Variables: *)
(* mode: caml *)
(* End: *)
--
2.1.0
From 9c054205bede2555ab96c7a03a21e8650a465308 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
From 7b01ce17d4caafdfa1f83a1d43b926c8ef2dd9c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphael.pinson@camptocamp.com>
Date: Tue, 25 Aug 2015 11:28:41 +0200
Subject: [PATCH 16/19] Shellvars: allow &&/|| in commands
---
lenses/shellvars.aug | 80 ++++++++++++++++++++++++-----------------
lenses/tests/test_shellvars.aug | 42 ++++++++++++++++++++--
2 files changed, 87 insertions(+), 35 deletions(-)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index f68f5bb..f7f4c47 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -106,28 +106,66 @@ module Shellvars =
. Util.del_str "return"
. ( Util.del_ws_spc . store Rx.integer )?
+ let action (operator:string) (lbl:string) (sto:lens) =
+ [ del (Rx.opt_space . operator . Rx.opt_space) (" " . operator . " ")
+ . label ("@".lbl) . sto ]
+
+ let action_pipe = action "|" "pipe"
+ let action_and = action "&&" "and"
+ let action_or = action "||" "or"
+
let condition =
- let action (operator:string) (lbl:string) =
- [ Sep.opt_space . Util.del_str operator . Sep.opt_space
- . label lbl . sto_to_semicol ]
- in let cond (start:string) (end:string) = [ label "type" . store start ]
- . Util.del_ws_spc . sto_to_semicol
- . Util.del_ws_spc . Util.del_str end
- . ( action "&&" "@and" | action "||" "@or" )*
+ let cond (start:string) (end:string) = [ label "type" . store start ]
+ . Util.del_ws_spc . sto_to_semicol
+ . Util.del_ws_spc . Util.del_str end
+ . ( action_and sto_to_semicol | action_or sto_to_semicol )*
in Util.indent . label "@condition" . (cond "[" "]" | cond "[[" "]]")
(* Entry types *)
let entry_eol_item (item:lens) = [ item . comment_or_eol ]
let entry_item (item:lens) = [ item ]
+ let entry_eol_nocommand =
+ entry_eol_item source
+ | entry_eol_item kv
+ | entry_eol_item unset
+ | entry_eol_item bare_export
+ | entry_eol_item builtin
+ | entry_eol_item return
+ | entry_eol_item condition
+ | entry_eol_item eval
+ | entry_eol_item alias
+
+ let entry_noeol_nocommand =
+ entry_item source
+ | entry_item kv
+ | entry_item unset
+ | entry_item bare_export
+ | entry_item builtin
+ | entry_item return
+ | entry_item condition
+ | entry_item eval
+ | entry_item alias
+
(* 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 let entry_eol = entry_eol_nocommand | entry_eol_item command
+ in let entry_noeol = entry_noeol_nocommand | entry_item command
+ in let entry = entry_eol | entry_noeol
+ in let pipe = action_pipe (entry_eol_item command | entry_item command)
+ in let and = action_and entry
+ in let or = action_or entry
in Util.indent . label "@command" . store (word - reserved_key)
. [ Sep.space . label "@arg" . sto_to_semicol]?
- . (pipe . (entry_eol_item command | entry_item command) )*
+ . ( pipe | and | or )?
+
+ let entry_eol = entry_eol_nocommand
+ | entry_eol_item command
+
+ let entry_noeol = entry_noeol_nocommand
+ | entry_item command
(************************************************************************
* Group: CONDITIONALS AND LOOPS
@@ -185,30 +223,6 @@ module Shellvars =
. entry+
. Util.indent . Util.del_str "}" . eol ]