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

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

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

File size: 890 bytes
Line 
1#
2# shell_join.rb
3#
4
5require 'shellwords'
6
7module Puppet::Parser::Functions
8 newfunction(:shell_join, :type => :rvalue, :doc => <<-EOS
9Builds a command line string from the given array of strings. Each array item is escaped for Bourne shell. All items are
10then joined together, with a single space in between.
11
12This 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
29end
30
31# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.