Last change
on this file since 30903 was 30903, checked in by davidb, 7 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
890 bytes
|
Line | |
---|
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 " +
|
---|
17 | "given (#{arguments.size} for 1)") if arguments.size != 1
|
---|
18 |
|
---|
19 | array = arguments[0]
|
---|
20 |
|
---|
21 | raise Puppet::ParseError, ("First argument is not an Array: #{array.inspect}") unless array.is_a?(Array)
|
---|
22 |
|
---|
23 | # explicit conversion to string is required for ruby 1.9
|
---|
24 | array = array.map { |item| item.to_s }
|
---|
25 | result = Shellwords.shelljoin(array)
|
---|
26 |
|
---|
27 | return result
|
---|
28 | end
|
---|
29 | end
|
---|
30 |
|
---|
31 | # vim: set ts=2 sw=2 et :
|
---|
Note:
See
TracBrowser
for help on using the repository browser.