Skip to content

Commit 09d16bb

Browse files
committed
avoid duplicate calls to env methods
1 parent 5fa26ba commit 09d16bb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/sshkit/command.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ def environment_string
162162
end
163163

164164
def with(&_block)
165-
return yield unless environment_hash.any?
166-
"( export #{environment_string} ; #{yield} )"
165+
env_string = environment_string
166+
return yield if env_string.empty?
167+
"( export #{env_string} ; #{yield} )"
167168
end
168169

169170
def user(&_block)
170171
return yield unless options[:user]
171-
"sudo -u #{options[:user].to_s.shellescape} #{environment_string + " " unless environment_string.empty?}-- sh -c #{yield.shellescape}"
172+
env_string = environment_string
173+
"sudo -u #{options[:user].to_s.shellescape} #{env_string + " " unless env_string.empty?}-- sh -c #{yield.shellescape}"
172174
end
173175

174176
def in_background(&_block)

0 commit comments

Comments
 (0)