[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [augeas-devel] Default label for a node in a path expression






On Mon, Jan 6, 2014 at 11:04 PM, David Lutterkort <lutter watzmann net> wrote:
Hi Raphael,


On Fri, Dec 20, 2013 at 2:24 PM, Raphaël Pinson <raphael pinson camptocamp com> wrote:
Hello,


There's regularly people asking how to write idempotent set expressions. With labeled nodes, we have the usual trick:

    set foo[.='bar'] 'bar'

which creates the 'foo' node with the 'bar' value if it doesn't exist.

Yes, I agree with both - that it's not wel supported right now, and that it is needed. The underlying problem is that there's no good way to infer from a path _expression_ where the newly created node  should go in case the path _expression_ doesn't match.

Rather than put something in the XPath language, I think it would be cleaner to do this explicitly in a dedicated command. I can think of a few ways to do that. The simplest would be a aug_set_or_create(expr, path, value) that goes something like this:

if aug_match(expr) == 1
  aug_set(expr, value)
elsif aug_match(expr) == 0
  aug_set(path, value)
else
  complain
end


Come to think of it, one very useful call for idempotent set commands is defnode, which I've been using extensively lately, such as in this situation: http://stackoverflow.com/a/21342882/232250

Defnode is very useful in that it sets a variable pointing to the newly create node (or to the nodeset already matching). The thing that's missing in defnode is precisely this default label thing, especially when dealing with seq entries.

So maybe rather than adding an aug_set_or_create() call, we could have a defnode_default() call, which would allow to pass a default path to defnode, the advantage being that we would always get a variable pointing to the resulting path.


--
Raphaël Pinson
Infrastructure Developer & Trainer
+33 479 26 57 93
+33 781 90 00 79

Camptocamp France
Savoie Technolac
BP 352
48, avenue du Lac du Bourget
73372 Le Bourget du Lac, Cedex
www.camptocamp.com

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]