forked from afeld/sshkit-interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.rb
More file actions
54 lines (43 loc) · 1.27 KB
/
Copy pathbackend.rb
File metadata and controls
54 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module SSHKit
module Interactive
class Backend < SSHKit::Backend::Printer
def run
instance_exec(host, &@block)
end
def within(directory, &_block)
(@pwd ||= []).push(directory.to_s)
yield
ensure
@pwd.pop
end
def as(who, &_block)
if who.is_a?(Hash)
@user = who[:user] || who['user']
@group = who[:group] || who['group']
else
@user = who
@group = nil
end
raise SSHKit::Interactive::Unsupported, 'Setting group (through `as`) is currently not supported' unless @group.nil?
yield
ensure
remove_instance_variable(:@user)
remove_instance_variable(:@group)
end
def execute(*args)
super
options = args.extract_options!
cmd = Command.new(host, command(args, options))
debug(cmd.to_s)
cmd.execute
end
def _unsupported_operation(*args)
raise SSHKit::Backend::MethodUnavailableError, 'SSHKit::Interactive does not support this operation.'
end
alias :upload! :_unsupported_operation
alias :download! :_unsupported_operation
alias :test :_unsupported_operation
alias :capture :_unsupported_operation
end
end
end