[augeas-devel] Dealing with empty values

Erinn Looney-Triggs erinn.looneytriggs at gmail.com
Thu Nov 18 16:55:15 UTC 2010


Searched around to try to find an answer to this but can't find anything
yet. I am writing a lense for /etc/default/useradd, pretty simple file
really key value separated by =. Here is the lense:
module Useradd =
autoload xfm

let eq = Util.del_str "="

let record =
  let value = store /[^ \t\n]+([ \t]+[^ \t\n]+)*/ in
  [ key Rx.word . eq . value . Util.eol ]

let lns = (record | Util.comment | Util.empty) *

let filter = incl "/etc/defaults/useradd" . Util.stdexcl

let xfm = transform lns filter

Here are the tests:

module Test_useradd =

let record = "GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
"

test Useradd.lns get record =
    { "GROUP" = "100" }
    { "HOME" = "/home" }
    { "INACTIVE" = "-1" }
    { "EXPIRE" = "" }
    { "SHELL" = "/bin/bash" }
    { "SKEL" = "/etc/skel" }
    { "CREATE_MAIL_SPOOL" = "yes" }

let comment ="# useradd defaults file
"

test Useradd.lns get comment =
  {"#comment" = "useradd defaults file"}

The problem is the EXPIRE= line. now I know that as my match currently
stands it is looking for a value not delimited by a \n or a space. So
clearly that isn't going to work but I can't figure out what will. Myabe
I am making this harder than it needs to be but storing \n as a value
works, sort of except that you now have a newline as a value. I guess
what I am looking fro is to replace the newline with "" as the value.
Del would seem to be right for that, but I can't seem to store a del.
Any help would be appreciated as I am pretty new to this.

Thanks,
-Erinn




More information about the augeas-devel mailing list