diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c4adaca..5c208ca5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ appear at the top. * allow command map entries (`SSHKit::CommandMap#[]`) to be Procs [PR #310]((https://github.com/capistrano/sshkit/pull/310) @mikz + * when using `SSHKit::CommandMap#prefix`, resolve the command through `SSHKit::CommandMap#[]` + [PR #311]((https://github.com/capistrano/sshkit/pull/311) + @mikz ## 1.8.1 diff --git a/lib/sshkit/command_map.rb b/lib/sshkit/command_map.rb index 88064ad0..49dad9f7 100644 --- a/lib/sshkit/command_map.rb +++ b/lib/sshkit/command_map.rb @@ -40,14 +40,10 @@ def initialize(value = nil) end def [](command) - if prefix[command].any? - prefixes = prefix[command].map(&TO_VALUE) - prefixes = prefixes.join(" ") + prefixes = prefix[command].map(&TO_VALUE) + cmd = TO_VALUE.(@map[command]) - "#{prefixes} #{command}" - else - TO_VALUE.(@map[command]) - end + [*prefixes, cmd].compact.join(' ') end def prefix diff --git a/test/unit/test_command_map.rb b/test/unit/test_command_map.rb index 90bddd89..98f1a604 100644 --- a/test/unit/test_command_map.rb +++ b/test/unit/test_command_map.rb @@ -30,7 +30,7 @@ def test_prefix map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec") map.prefix[:rake].push("bundle exec") - assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake" + assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec /usr/bin/env rake" end def test_prefix_procs @@ -38,7 +38,7 @@ def test_prefix_procs map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec") map.prefix[:rake].push(proc{ "bundle exec" }) - assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake" + assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec /usr/bin/env rake" end def test_prefix_unshift @@ -46,7 +46,7 @@ def test_prefix_unshift map.prefix[:rake].push("bundle exec") map.prefix[:rake].unshift("/home/vagrant/.rbenv/bin/rbenv exec") - assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake" + assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec /usr/bin/env rake" end def test_indifferent_setter @@ -62,8 +62,15 @@ def test_indifferent_prefix map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec") map.prefix["rake"].push("bundle exec") - assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake" + assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec /usr/bin/env rake" end + def test_prefix_setter + map = CommandMap.new({}) + map[:rake] = 'rake2.2' + map.prefix[:rake].push('bundle exec') + + assert_equal map[:rake], 'bundle exec rake2.2' + end end end