Sha256: 7ea912b7d973af41190ffc798a998254c9914cb7b7984342ebbae0f4f97b973b
Contents?: true
Size: 1.98 KB
Versions: 2
Compression:
Stored size: 1.98 KB
Contents
# frozen_string_literal: true require "websocket-client-simple" require "thor" require "readline" require_relative "../session" require_relative "./constants" module NeetoDeploy class CLI module Exec class Base < CLI::Base include Constants include Session attr_reader :app_name def initialize(app_name) super() @app_name = app_name end def process! puts "Opening console for #{app_name}" response = send_post_request( console_session_create_url, { # TODO refactor app_slug to app_name in dashboard app app_slug: app_name, } ) ui.error(response) and return unless response.success? console_token = response.parsed_response["console_token"] ws = WebSocket::Client::Simple.connect "wss://neeto-deploy-lc.neetodeployapp.com/cli_console?deployment_name=#{app_name}&console_token=#{console_token}" prompt = '' ws.on :message do |msg| message = msg.data if message.to_s.eql?("{\"exitCode\":0,\"signal\":0}") exit 0 end cmd = message[0] if cmd == "1" prompt = "\u001b[2K\u001b[0G#{message.delete_prefix("1").split("\r\n").last}" print message.delete_prefix("1") end end ws.on :open do end ws.on :close do |e| puts e exit 1 end ws.on :error do |e| puts e puts "MyserverBackend>> Close entered. Last error:#{$!.class}:#{$!.to_s};Module:#{$0};" $@.each { |backtrace| puts backtrace } exit 1 end trap("SIGINT") do Thread.new { ws.send "4" } end loop do sleep 0.1 input = Readline.readline(prompt, true) ws.send "1" + input end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
neetodeploy-1.1.0 | lib/neeto_deploy/cli/exec/base.rb |
neetodeploy-1.0.10 | lib/neeto_deploy/cli/exec/base.rb |