Skip to content

Commit a13b366

Browse files
Michal Cichramikz
Michal Cichra
authored andcommitted
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 b8817e6 commit a13b366

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ appear at the top.
1818
@beatrichartz
1919
* `SSHKit::Backend::Printer#test` now always returns true
2020
[PR #312](https://github.com/capistrano/sshkit/pull/312) @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
### New features
2326

lib/sshkit/command_map.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,10 @@ def initialize(value = nil)
3838
end
3939

4040
def [](command)
41-
if prefix[command].any?
42-
prefixes = prefix[command].map(&TO_VALUE)
43-
prefixes = prefixes.join(" ")
41+
prefixes = prefix[command].map(&TO_VALUE)
42+
cmd = TO_VALUE.(@map[command])
4443

45-
"#{prefixes} #{command}"
46-
else
47-
TO_VALUE.(@map[command])
48-
end
44+
[*prefixes, cmd].compact.join(' ')
4945
end
5046

5147
def prefix

test/unit/test_command_map.rb

+12-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,7 +62,7 @@ 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

6868
def test_prefix_initialization_is_thread_safe
@@ -74,5 +74,13 @@ def test_prefix_initialization_is_thread_safe
7474
end
7575
threads.each(&:join)
7676
end
77+
78+
def test_prefix_setter
79+
map = CommandMap.new({})
80+
map[:rake] = 'rake2.2'
81+
map.prefix[:rake].push('bundle exec')
82+
83+
assert_equal map[:rake], 'bundle exec rake2.2'
84+
end
7785
end
7886
end

0 commit comments

Comments
 (0)