Feature #2990
There's a split(), but no combine()
| Status: | Needs More Information | Start date: | 12/28/2009 | |
|---|---|---|---|---|
| Priority: | Low | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | - | |||
| Target version: | - | |||
| Affected Puppet version: | 0.25.4 | Branch: | ||
| Keywords: | ||||
| Votes: | 2 |
Description
The split function is nice, but it would be logical to me if there was also a combine() function, which did about the same, only the other way around. Is that very hard to add?
History
Updated by Markus Roberts over 2 years ago
- Status changed from Unreviewed to Needs More Information
If you just want to combine various segments of an array into a string you can write:
sprintf("%s",my_array)
If you want something that provides delimiters a'la ruby’s join, it should be trivial to add, perhaps:
module Puppet::Parser::Functions
newfunction(:join, :type => :rvalue,
:doc => "Join a list of strings with an optional delimiter."
) do |args|
raise Puppet::ParseError, 'join() takes 1 or 2 arguments' unless 1..2.include? args.length
args.first.join args.last
end
end
What’s the use case?
Updated by Tim Stoop over 2 years ago
The use case is where I’m currently using inline_template(“<%= arr.join(‘,’) %>”). It’s more an aesthetic request, I guess, since there’s a puppet native split(). I’m guessing that could be done with a inline_template as well.
Updated by Tim Stoop about 2 years ago
- Priority changed from Normal to Low
- Affected Puppet version changed from 0.25.1 to 0.25.4
Also, that goes wrong when you’re trying to join a non-array, so I need to build in more logic. Would be nice to have as a function.
Updated by Mike Cooper over 1 year ago
I would also appreciate this feature.
My use case: I am writing a sudo module that will take a list of commands that a user is allowed to run. I would like to be able to pass either a single command as a string, or multiple commands as a list of strings. It doesn’t make much sense to rely on the user to pass a string value containing a list of comma separated commands instead of a list value, like is the normal case in puppet.
This use case would also benefit from the function being smart enough to pass a plain string (instead of a list of strings) through the function unmodified.