<div dir="ltr">Hi there,<br><br>David implemented the "mv" function yesterday so I'm playing a bit with it today. <br><br><br>============================================================<br>module CommentTest =<br>
<br>   autoload xfm<br><br>   let c_key (kw:string) = Util.del_str kw . label ("." . kw)<br><br>   let entry   = [ key "field" . Util.del_str "=" . store /.*/ . Util.del_str "\n" ]<br>
   let c_entry = [ Util.del_str "#" . c_key "field" . Util.del_str "=" . store /.*/ . Util.del_str "\n" ]<br><br>   let lns = (entry | c_entry)*<br><br><br>   let filter = (incl "/commenttest")<br>
<br>   let xfm = transform lns filter<br>============================================================<br><br>$ cat fakeroot/commenttest<br>field=toto<br>field=titi<br><br>$ augtool -I . -r fakeroot/<br>augtool> print /files/commenttest/<br>
/files/commenttest<br>/files/commenttest/field[1] = "toto"<br>/files/commenttest/field[2] = "titi"<br>augtool> mv /files/commenttest/field[1] /files/commenttest/.field<br>augtool> save<br>augeas.c:908 Fixme: Multiple transforms for /files<br>
augeas.c:908 Fixme: Multiple transforms for /files<br>Saving failed<br>augtool> quit<br><br> $ cat fakeroot/commenttest<br>field=titi<br>#field=toto<br><br>============================================================<br>
<br><br>There's a few things to note here:<br>* mv works ! Thank you David :)<br>* save works but is not happy :(<br>* "field=toto" got moved from 1st place to 2nd placed when it got commented. This is a side effect to this (un)commenting method I hadn't considered.<br>
* dealing with key in the lens is quite tricky. While it's possible to declare a c_key function, it will only take a string, since the contents of Util.del_str kw cannot be assigned to label currently. The following will NOT work:<br>
<br>============================================================<br>let entry_gen (kw:string) = [ key kw . Util.del_str "=" . store /.*/ . Util.del_str "\n" ]<br>let c_entry_gen (kw:string) = [ Util.del_str "#" . c_key kw . Util.del_str "=" . store /.*/ . Util.del_str "\n" ]<br>
<br>let field = "field1"<br>            | "field2"<br><br>let entry = entry_gen field<br>let c_entry = c_entry_gen field<br>============================================================<br><br>The reason why it doesn't work is quite obvious: field is not a string, but a regexp. For it to work, entry_gen and c_entry_gen would have to take regexps instead of strings, but then c_key would have to take a regexp, too, which is not possible.<br>
<br><br><br>Just a few thoughts...<br><br><br><br>Raphaël<br></div>