41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/wokku/commands/shell.rb', line 41
def run!(mode:, target_kind:, target:, argv:, force_tty:)
resource_path = target_kind == :app ? "/apps/#{target}" : "/databases/#{target}"
resource = api(:get, resource_path)
server_id = resource["server_id"] or abort "could not resolve server for #{target}"
token = Wokku::Config.api_token or abort "not logged in — run `wokku auth:login`"
cable_url = derive_cable_url(Wokku::Config.api_url)
cable = Wokku::CableClient.new(url: cable_url, token: token)
cable.subscribe(channel: "TerminalChannel", params: { server_id: server_id })
tty = force_tty.nil? ? $stdout.tty? : force_tty
session = Wokku::PtySession.new(cable: cable, tty: tty)
session.start!(mode: mode, target: target, argv: argv)
session.run
cable.close
exit(session.exit_code || 0)
end
|