aboutsummaryrefslogtreecommitdiffstats
path: root/main/augeas/0012-Shellvars-Allow-almost-any-command.patch
blob: 7338c27c84b06a7976cf98803d2443d3b44a3617 (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
74
75
76
77
78
79
80
81
82
83
84
85
From 9d896f124404865e996042de74347644a2dd2e3a 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

    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(+)

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
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -107,6 +107,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/
+    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
         | entry_eol_item condition
+        | 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
         | entry_item condition
+        | 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
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -604,6 +604,17 @@ esac\n" =
     { "@or" = "or that" }
   }
 
+(* Test: Shellvars.lns
+     Parse (almost) any command *)
+test Shellvars.lns get "echo foobar 'and this is baz'
+/usr/local/bin/myscript.sh with args\n" =
+  { "@command" = "echo"
+    { "@arg" = "foobar 'and this is baz'" }
+  }
+  { "@command" = "/usr/local/bin/myscript.sh"
+    { "@arg" = "with args" }
+  }
+
 (* Local Variables: *)
 (* mode: caml       *)
 (* End:             *)
-- 
2.1.0