Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / shell_join.rb
1
2 require 'shellwords'
3 #
4 # shell_join.rb
5 #
6 module Puppet::Parser::Functions
7   newfunction(:shell_join, :type => :rvalue, :doc => <<-DOC
8     @summary
9     Builds a command line string from the given array of strings.
10     Each array item is escaped for Bourne shell. All items are then joined together, with a single space in between.
11     This function behaves the same as ruby's Shellwords.shelljoin() function
12
13     @return
14       a command line string
15   DOC
16              ) do |arguments|
17
18     raise(Puppet::ParseError, "shell_join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
19
20     array = arguments[0]
21
22     raise Puppet::ParseError, "First argument is not an Array: #{array.inspect}" unless array.is_a?(Array)
23
24     # explicit conversion to string is required for ruby 1.9
25     array = array.map { |item| item.to_s }
26     result = Shellwords.shelljoin(array)
27
28     return result
29   end
30 end
31
32 # vim: set ts=2 sw=2 et :