class Pytty::Client::Cli::RunCommand

Public Instance Methods

execute() click to toggle source
# File lib/pytty/client/cli/run_command.rb, line 19
def execute
  Async.run do |task|
    response, body = Pytty::Client::Api::Yield.run id: name, cmd: cmd_list, env: {}
    unless response.status == 200
      puts body
      exit 1
    end
    process_yield = Pytty::Client::ProcessYield.from_json body

    attach_task = unless detach?
      task.async do
        process_yield.attach interactive: interactive?
        process_yield.rm
      end
    end

    response, body = process_yield.spawn tty: tty?, interactive: interactive?
    if response.status == 200
      if detach?
        puts process_yield.id
      end
    else
      puts body
      attach_task.stop
      print "\r" unless detach?
    end
  end
end