Sha256: e95b65b2fa5395302dc9567087cc434a4f402f4bf2a2abd6a78b5356d0b6c802

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

# frozen_string_literal: true
require 'async'
require 'async/http'
require 'async/http/internet'
require 'json'

module Pytty
  module Client
    module Cli
      class RmCommand < Clamp::Command
        parameter "[ID] ...", "id"
        option ["--all"], :flag, "all"

        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
            for id in ids do
              response, body = Pytty::Client::Api::Rm.run id: id

              if response.status == 200
                puts id
              else
                puts response.read
                exit 1
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pytty-0.5.0 lib/pytty/client/cli/rm_command.rb