On 11/18/2010 10:10 AM, Raphaël Pinson wrote: > Hi Erinn, > > On Thu, Nov 18, 2010 at 5:55 PM, Erinn Looney-Triggs > <[email protected] <mailto:[email protected]>> > wrote: > > 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. > > > > I'd say the simplest way to do that would be to make value optional: > > let record = > let value = store /[^ \t\n]+([ \t]+[^ \t\n]+)*/ in > [ key Rx.word . eq . value? . Util.eol ] > > and then: > > test Useradd.lns get record = > { "GROUP" = "100" } > { "HOME" = "/home" } > { "INACTIVE" = "-1" } > > { "EXPIRE" } > > { "SHELL" = "/bin/bash" } > > { "SKEL" = "/etc/skel" } > > { "CREATE_MAIL_SPOOL" = "yes" } > > > Since "=" is mandatory in your file, you can consider that an empty > value can be represented by a flag. > > > Raphaël > >
Great thanks for that, solves the issue very nicely. I will be opening up another bug with the lens and tests here in a few minutes. Thanks again, -Erinn
_______________________________________________ augeas-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/augeas-devel
