Feature #2491
The regsubst() function should be able to operate on arrays
| Status: | Closed | Start date: | 08/04/2009 | ||
|---|---|---|---|---|---|
| Priority: | Normal | Due date: | |||
| Assignee: | % Done: | 80% | |||
| Category: | functions | ||||
| Target version: | 2.6.0 | ||||
| Affected Puppet version: | 0.25.0rc1 | Branch: | |||
| Keywords: | |||||
Description
It would be nice if one could give an array to regsubst(), and make it perform the substitution on each element of that array.
One, perhaps non-obvious, use case is to have a definition that takes an array as parameter, and have it “loop” over that by giving it as the name parameter to a helper definition, like this:
define my_define($param, ...)
{
$x = regsubst($param, ".*", "$name//\\&")
my_define_helper {
$x: ...;
}
...
}
define my_define_helper(...)
{
$n = regsubst($name, '^(.*)//(.*)$', '\1')
$p = regsubst($name, '^(.*)//(.*)$', '\2')
# Do things with $n and $p, which now are the $name and one
# element of $param from my_define, respectively.
}
my_define {
"foo": param => ["a", "b", "c"], ...;
"bar": param => ["a", "b", "c"], ...;
}
One can already do the looping today, but only as long as the param parameters to My_define[foo] and My_define[bar] doesn’t have any elements in common. (This use case came up in puppet-users recently, where the poster wanted a definition for managing PGP keystores, where one parameter would be an array of keys. http://groups.google.com/group/puppet-users/browse_thread/thread/d3e85f7869f66ed1)
History
#1
Updated by Thomas Bellman almost 4 years ago
Sigh This tracker doesn’t seem to be made for pasting code into the reports. It does really strange things to the formatting… The two code chunks and the paragraph inbetween is really supposed to be a single code chunk, and the numerated list in the paragraph is actually two lines of comments.
#2
Updated by James Turnbull almost 4 years ago
- Status changed from Unreviewed to Needs Decision
- Target version set to 0.25.0
Thomas – you just need to use the pre blocks.
#3
Updated by Luke Kanies almost 4 years ago
Is this particularly important for 0.25? Is it a small enough change that it deserves to be in after the rc1?
#4
Updated by Thomas Bellman almost 4 years ago
- Target version changed from 0.25.0 to 2.6.0
Wait until after 0.25.0, in my opinion.
#5
Updated by Thomas Bellman almost 4 years ago
- File 0001-Make-regsubst-function-operate-on-arrays-feature.patch
added - Status changed from Needs Decision to Ready For Checkin
The attached patch has been posted to puppet-dev, and Luke has given it +1.
#6
Updated by James Turnbull almost 4 years ago
- Status changed from Ready For Checkin to Closed
Pushed in commit:e51754a951225e586586566f536e7ba16db7db27 in branch master.
#7
Updated by James Turnbull over 3 years ago
- Status changed from Closed to Accepted
- Assignee changed from Thomas Bellman to James Turnbull
Something is wrong with the commit. Assigned to me to check.
#8
Updated by James Turnbull over 3 years ago
- Status changed from Accepted to Closed
Wrong commit – correct is commit:630407d527905a9c874ae4b32a62849fdf6864b7 in branch master.