Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / shell_escape.rb
1 require 'shellwords'
2 #
3 # shell_escape.rb
4 #
5 module Puppet::Parser::Functions
6   newfunction(:shell_escape, :type => :rvalue, :doc => <<-DOC
7     @summary
8       Escapes a string so that it can be safely used in a Bourne shell command line.
9
10     @return
11       A string of characters with metacharacters converted to their escaped form.
12
13     >* Note:* that the resulting string should be used unquoted and is not intended for use in double quotes nor in single
14     quotes.
15
16     This function behaves the same as ruby's Shellwords.shellescape() function.
17   DOC
18              ) do |arguments|
19
20     raise(Puppet::ParseError, "shell_escape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
21
22     # explicit conversion to string is required for ruby 1.9
23     string = arguments[0].to_s
24
25     result = Shellwords.shellescape(string)
26
27     return result
28   end
29 end
30
31 # vim: set ts=2 sw=2 et :