Skip to content

Commit

Permalink
interpolate Array arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
sshaw committed Nov 15, 2013
1 parent 940664e commit c743ecc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/cocaine/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions spec/cocaine/command_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c743ecc

Please sign in to comment.