[augeas-devel] [PATCH] An alias can also be a command containing spaces. + Add doc. There's an edge case when the command contains a comma (which is valid if surrounded in quotes) but it can be confusing for regexps.
Mathieu Arnold
mat at mat.cc
Wed Nov 3 17:10:48 UTC 2010
From: Mathieu Arnold <mat at FreeBSD.org>
---
lenses/aliases.aug | 48 +++++++++++++++++++++++++++++++++++++---
lenses/tests/test_aliases.aug | 11 ++++++++-
2 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/lenses/aliases.aug b/lenses/aliases.aug
index 44f83b9..2ab2c2d 100644
--- a/lenses/aliases.aug
+++ b/lenses/aliases.aug
@@ -2,17 +2,57 @@
module Aliases =
autoload xfm
+ (************************************************************************
+ * Group: USEFUL PRIMITIVES
+ *************************************************************************)
+
+ (* Group: basic tokens *)
+
+ (* Variable: word *)
let word = /[^, \t\n]+/
- let name = /([^ \t\n#:@]+|"[^"\n]*")/ (* " make emacs calm down *)
+ (* Variable: name *)
+ let name = /([^ \t\n#:|@]+|"[^"|\n]*")/ (* " make emacs calm down *)
- let colon = del /:[ \t]+/ ":\t"
- let eol = Util.eol
+ (* Variable: command
+ * a command can contain spaces, if enclosed in double quotes, the case
+ * without spaces is taken care with <word>
+ *)
+ let command = /\|"[^,"\n]+"/
+
+ (* Group: Comments and empty lines *)
+ (* View: eol *)
+ let eol = Util.eol
+ (* View: comment *)
let comment = Util.comment
+ (* View: empty *)
let empty = Util.empty
+ (* Group: separators *)
+ (* View: colon
+ * Separation between the alias and it's destinations
+ *)
+ let colon = del /:[ \t]+/ ":\t"
+ (* View: comma
+ * Separation between multiple destinations
+ *)
let comma = del /,[ \t]*(\n[ \t]+)?/ ", "
- let value_list = Build.opt_list ([ label "value" . store word]) comma
+
+ (* Group: alias *)
+
+ (* View: destination
+ * Can be either a word (no spaces included) or a command with spaces
+ *)
+ let destination = ( word | command )
+
+ (* View: value_list
+ * List of destinations
+ *)
+ let value_list = Build.opt_list ([ label "value" . store destination]) comma
+
+ (* View: alias
+ * a name with one or more destinations
+ *)
let alias = [ seq "alias" .
[ label "name" . store name ] . colon .
value_list
diff --git a/lenses/tests/test_aliases.aug b/lenses/tests/test_aliases.aug
index 4041f8a..256dfc6 100644
--- a/lenses/tests/test_aliases.aug
+++ b/lenses/tests/test_aliases.aug
@@ -12,6 +12,9 @@ postmaster: root
bin: root, adm
daemon: root
adm: root
+file: /var/foo
+pipe1: |/bin/ls
+pipe2: |\"/usr/bin/ls args\"
"
test Aliases.lns get file =
{ }
@@ -32,9 +35,15 @@ adm: root
{ "value" = "root" } }
{ "5" { "name" = "adm" }
{ "value" = "root" } }
+ { "6" { "name" = "file" }
+ { "value" = "/var/foo" } }
+ { "7" { "name" = "pipe1" }
+ { "value" = "|/bin/ls" } }
+ { "8" { "name" = "pipe2" }
+ { "value" = "|\"/usr/bin/ls args\"" } }
test Aliases.lns put file after
- rm "/4" ; rm "/5" ;
+ rm "/4" ; rm "/5" ; rm "/6" ; rm "/7" ; rm "/8" ;
set "/1/value[2]" "barbar" ;
set "/3/value[2]" "ruth"
= "#
--
1.7.3.2
More information about the augeas-devel
mailing list