-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "else" operator to augeas path-filter expressions (priority selector) #692
Conversation
Wouldn't that be a |
For this Also, the
In which case the 1st non-empty nodeset is selected. Admittedly, that's getting pretty complex for a path-filter, but the logic supports it out-of-the-box. |
I am not sure that Furthermore inside a If you want 'take the first thing that matches' functionality, you'd want an
That evaluates both the left and right operand of
What
You can write that down already, too, but it's not entirely straightforward:
So, I am not convinced that |
The More practically, it would be used in those situtations where exactly one node is required - such as the eg. an expression:
matches both nodes and return a nodeset of 2 nodes. By contrast, when
matches only I have to admit that I had not considered your approach of appending another predicate
Even this is not quite the same as For a practical example (albeit contrived), consider the case where I want to set my default-route on a network device. I could do this with
The key difference between I note that it is possible to construct this using other logic, as you have demonstrated. I had not considered using the I will update this pull-request to allow At the moment, this is giving rise to some issues around the |
ce914a4
to
fdc10c9
Compare
I have updated this pull-request with a modified
This allows alternate paths to be chosen, depending on what is already there, as may be dictated by the filesystem structure. I have made some changes to eval_binary() around the handling of the locpath_trace variable, so
The code around eval_union() has also be modified, such that the following statement results in a consistant error, rather than an abort
Although it may be possible to construct path-expressions which give similar results to the
I very much appreciate your feedback and comments, which have already made this pull-request more usable than the original. |
fdc10c9
to
738bb64
Compare
If there are no ongoing objections, can this Pull Request please be accepted? |
Sorry for the slow reaction time. @lutter do you want to validate this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am convinced, I can see how this makes some path manipulations possible, and cleaner/easier to write.
…tor) - expanded to include nodeset expressions
This Pull Request adds a new binary operator to path-filter expressions.
The new operator is currently called
else
.The existing binary operators
and
andor
effectively act on 'sets' of nodes.Given a filter-expression of the form:
eg.
nodeset_a and nodeset_b refer to a subset of
*
*
represents all nodes at this level of the tree.The
or
operator forms a union of nodeset_a and nodeset_bGiven a filter-expression:
The
and
operator forms an intersection of nodeset_a and nodeset_bThe new binary operator
else
also deals with nodesets.Given a filter-expression:
The
else
operator acts as a 'selector' or 'order-of-priority' between alternate nodesets.nodeset_a will be selected as long as it is not empty. If nodeset_a is empty, nodeset_b is selected.
A typical application for this would be in a command such as
set
that requires exactly one node to match.For the case where both nodeset_a and nodeset_b exist, contain a single node, and are not the same node:
or
operator is used this will result in a nodeset with 2 nodes.else
operator is used, only nodeset_a will be selected, which results in a nodeset with 1 node.