source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/shell_escape.rb@ 30960

Last change on this file since 30960 was 30960, checked in by davidb, 8 years ago

Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster

File size: 782 bytes
Line 
1#
2# shell_escape.rb
3#
4
5require 'shellwords'
6
7module Puppet::Parser::Functions
8 newfunction(:shell_escape, :type => :rvalue, :doc => <<-EOS
9Escapes a string so that it can be safely used in a Bourne shell command line.
10
11Note that the resulting string should be used unquoted and is not intended for use in double quotes nor in single
12quotes.
13
14This function behaves the same as ruby's Shellwords.shellescape() function.
15 EOS
16 ) do |arguments|
17
18 raise(Puppet::ParseError, "shell_escape(): Wrong number of arguments " +
19 "given (#{arguments.size} for 1)") if arguments.size != 1
20
21 # explicit conversion to string is required for ruby 1.9
22 string = arguments[0].to_s
23
24 result = Shellwords.shellescape(string)
25
26 return result
27 end
28end
29
30# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.