Class: Pytty::Client::Cli::RmCommand

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/pytty/client/cli/rm_command.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



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
# File 'lib/pytty/client/cli/rm_command.rb', line 14

def execute
  ids = if all?
    process_yield_jsons = Async.run do
      Pytty::Client::Api::Ps.run
    end.wait
    process_yield_jsons.map do |json|
      json.fetch("id")
    end
  else
    id_list
  end

  Async.run do
    internet = Async::HTTP::Internet.new
    headers = [['accept', 'application/json']]
    body = {}.to_json

    for id in ids do
      response = internet.post("#{Pytty::Client.host_url}/v1/rm/#{id}", headers, [body])
      if response.status == 200
        puts id
      else
        puts response.read
        exit 1
      end
    end
  ensure
    internet.close
  end
end