Skip to content

Commit 1d95fcd

Browse files
author
Michal Cichra
committed
command map prefix should still use map command
it is valid use case to set both command map and prefix in case of using different binary, the map should still be active and prefix should be applied as extra so following example correclty executes rake2.2 within bundler: SSHKit.config.command_map[:rake] = 'rake2.2' SSHKit.config.command_map.prefix[:rake] = 'bundle exec' Only drawback is, that resulting command will be: bundle exec /usr/bin/env rake2.2
1 parent 7ea7a1b commit 1d95fcd

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ appear at the top.
1818
* allow command map entries (`SSHKit::CommandMap#[]`) to be Procs
1919
[PR #310]((https://github.com/capistrano/sshkit/pull/310)
2020
@mikz
21+
* when using `SSHKit::CommandMap#prefix`, resolve the command through `SSHKit::CommandMap#[]`
22+
[PR #311]((https://github.com/capistrano/sshkit/pull/311)
23+
@mikz
2124

2225
## 1.8.1
2326

lib/sshkit/command_map.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,10 @@ def initialize(value = nil)
4040
end
4141

4242
def [](command)
43-
if prefix[command].any?
44-
prefixes = prefix[command].map(&TO_VALUE)
45-
prefixes = prefixes.join(" ")
43+
prefixes = prefix[command].map(&TO_VALUE)
44+
cmd = TO_VALUE.(@map[command])
4645

47-
"#{prefixes} #{command}"
48-
else
49-
TO_VALUE.(@map[command])
50-
end
46+
[*prefixes, cmd].compact.join(' ')
5147
end
5248

5349
def prefix

test/unit/test_command_map.rb

+11-4
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ def test_prefix
3030
map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec")
3131
map.prefix[:rake].push("bundle exec")
3232

33-
assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
33+
assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec /usr/bin/env rake"
3434
end
3535

3636
def test_prefix_procs
3737
map = CommandMap.new
3838
map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec")
3939
map.prefix[:rake].push(proc{ "bundle exec" })
4040

41-
assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
41+
assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec /usr/bin/env rake"
4242
end
4343

4444
def test_prefix_unshift
4545
map = CommandMap.new
4646
map.prefix[:rake].push("bundle exec")
4747
map.prefix[:rake].unshift("/home/vagrant/.rbenv/bin/rbenv exec")
4848

49-
assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
49+
assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec /usr/bin/env rake"
5050
end
5151

5252
def test_indifferent_setter
@@ -62,8 +62,15 @@ def test_indifferent_prefix
6262
map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec")
6363
map.prefix["rake"].push("bundle exec")
6464

65-
assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
65+
assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec /usr/bin/env rake"
6666
end
6767

68+
def test_prefix_setter
69+
map = CommandMap.new({})
70+
map[:rake] = 'rake2.2'
71+
map.prefix[:rake].push('bundle exec')
72+
73+
assert_equal map[:rake], 'bundle exec rake2.2'
74+
end
6875
end
6976
end

0 commit comments

Comments
 (0)