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