-
Notifications
You must be signed in to change notification settings - Fork 9
Dealing with comments
raphink edited this page Jan 4, 2013
·
1 revision
This page intends to list the various ways to deal with comments in Augeas lenses, and the pros and cons of these methods.
This page will list different trees to represent the following file (located as /path/to/file):
Note: the examples beneath are experimental attempts by the author of this post. The Augeas development team does not necessarily agree with these choices.
The first lenses made for Augeas ignored all comments. Comments were deleted altogether with empty lines.
/files/path/to/file/field1 = "value1" (null) (null)
let comment = [ del /(#.*|[ \t]*)\n/ "\n" ]
- Pros: Comments are absent of the tree, since they are not useful values. They're easy to deal with this way.
- Cons: Comments are absent of the tree. They cannot be seen, added or modified with Augeas.
let comment = [ label "comment" . del /#[ \t]*/ "#" . store /([^ \t\n][^\n]*)?/ . eol ] let empty = [ del /[ \t]*/ "" . eol ]
- Pros:
- Comments are present in tree.
- They are easy to filter.
- They are easy to find, add and modify
- Cons:
- Commented values are hard to uncomment (you have to get the content, parse it inside your program and create all the nodes in the augeas tree, and then remove the comment)
- Values are hard to comment (you have to concatenate the values properly, so you need to know the format, and then remove all the nodes you have commented)
let commented = [ label "commented" . del /#[ \t]*/ "# " ] let comment = [ label "comment" . del /#[ \t]*/ "# " . store ( /[^ \t\n][^\n]*)/ - /[ \t]*value[ \t]*=[ \t]*[^# \t\n][^#\n]*/ ) . Util.del_str "\n" ] let record = [ seq "record" . commented? . [ key "value" . del /[ \t]*=[ \t]*/ " = " . store /[^# \t\n][^#\n]*/ ] . Util.del_str "\n" ]
- Pros:
- Commented values are easy to uncomment: it is a matter of a rm on the 'commented' node.
- Values are easy to comment: you only need to create a 'commented' node in the tree.
- Representing commented values (e.g. in a GUI) is very easy.
- Cons:
- Developers using such a lens have to check for the 'commented' flag before using the value. This might lead to mistakenly considering commented values as uncommented.
- Defining pure comments is made much harder (they have to be defined by difference with any possible commented value)
/files/path/to/file/field1 = "value1" /files/path/to/file/commented /files/path/to/file/commented/field2 = "value2" /files/path/to/file/comment = "a standard comment"
- Pros:
- Commented values are easy to see in the tree.
- There is no risk for developers to use commented values as uncommented ones.
- Cons:
- It is hard to comment/uncomment values.
/files/path/to/file/field1 = "value1" /files/path/to/file/.field2 = "value2" /files/path/to/file/comment = "a standard comment"
- Pros:
- Commented values are easy to see in the tree.
- There is no risk for developers to use commented values as uncommented ones.