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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/aptible/cli/subcommands/ssh.rb', line 7
def self.included(thor)
thor.class_eval do
include Helpers::Operation
include Helpers::App
desc 'ssh [COMMAND]', 'Run a command against an app'
long_desc <<-LONGDESC
Runs an interactive command against a remote Aptible app
If specifying an app, invoke via: aptible ssh [--app=APP] COMMAND
LONGDESC
app_options
option :force_tty, type: :boolean
def ssh(*args)
app = ensure_app(options)
tty_mode, interactive = if options[:force_tty]
['-tt', true]
elsif [STDIN, STDOUT].all?(&:tty?)
['-t', true]
else
['-T', false]
end
op = app.create_operation!(
type: 'execute',
command: command_from_args(*args),
interactive: interactive
)
ENV['ACCESS_TOKEN'] = fetch_token
opts = ['-o', 'SendEnv=ACCESS_TOKEN', tty_mode]
exit_with_ssh_portal(op, *opts)
end
private
def command_from_args(*args)
args.empty? ? '/bin/bash' : Shellwords.join(args)
end
end
end
|