diff --git a/lib/cocaine/command_line.rb b/lib/cocaine/command_line.rb index 25bcc37..330d850 100644 --- a/lib/cocaine/command_line.rb +++ b/lib/cocaine/command_line.rb @@ -125,7 +125,11 @@ def interpolate(pattern, interpolations) interpolations = stringify_keys(interpolations) pattern.gsub(/:\{?(\w+)\b\}?/) do |match| key = match.tr(":{}", "") - interpolations.key?(key) ? shell_quote(interpolations[key]) : match + if interpolations.key?(key) + Array(interpolations[key]).map { |value| shell_quote(value) }.join(" ") + else + match + end end end diff --git a/spec/cocaine/command_line_spec.rb b/spec/cocaine/command_line_spec.rb index 1e9a2cd..7bcacbd 100644 --- a/spec/cocaine/command_line_spec.rb +++ b/spec/cocaine/command_line_spec.rb @@ -78,6 +78,11 @@ command.run(:hello_world => "Hello, world").should match(/Hello, world/) end + it "interpolates any Array arguments when running a command" do + command = Cocaine::CommandLine.new("echo", "Hello :worlds and :dwarfs") + command.command(:worlds => %w[mercury venus earth], :dwarfs => "pluto").should == "echo Hello 'mercury' 'venus' 'earth' and 'pluto'" + end + it "quotes command line options differently if we're on windows" do on_windows! cmd = Cocaine::CommandLine.new("convert",