Sha256: a1d104be0f72e987b3745302e48ac0b2665ac1068e5af56266ead5b24f1390d4

Contents?: true

Size: 821 Bytes

Versions: 62

Compression:

Stored size: 821 Bytes

Contents

require 'terminal-table'

module Opsicle
  class List
    attr_reader :client

    def initialize(environment)
      @client = Client.new(environment)
    end

    def execute(options={})
      stack_ids = get_stacks
      apps = get_apps(stack_ids)
      print(apps)
    end

    def get_stacks
      client.api_call('describe_stacks')[:stacks].map{|s| s[:stack_id] }
    end

    def get_apps(stack_ids)
      stack_ids.map{ |stack_id| apps_for_stack(stack_id) }.flatten
    end

    def apps_for_stack(stack_id)
      client.api_call('describe_apps', stack_id: stack_id)[:apps]
    end

    def print(apps)
      puts Terminal::Table.new headings: ['Name', 'Stack Id', 'App Id'], rows: app_data(apps)
    end

    def app_data(apps)
      apps.map{|app| [app[:name], app[:stack_id], app[:app_id]] }
    end

  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
opsicle-2.15.0 lib/opsicle/commands/list.rb
opsicle-2.14.2 lib/opsicle/commands/list.rb
opsicle-2.14.1 lib/opsicle/commands/list.rb
opsicle-2.14.0 lib/opsicle/commands/list.rb
opsicle-2.13.1 lib/opsicle/commands/list.rb
opsicle-2.13.0 lib/opsicle/commands/list.rb
opsicle-2.12.5 lib/opsicle/commands/list.rb
opsicle-2.12.3 lib/opsicle/commands/list.rb
opsicle-2.12.2 lib/opsicle/commands/list.rb
opsicle-2.12.1 lib/opsicle/commands/list.rb
opsicle-2.12.0 lib/opsicle/commands/list.rb
opsicle-2.11.3 lib/opsicle/commands/list.rb
opsicle-2.11.1 lib/opsicle/commands/list.rb
opsicle-2.11.0 lib/opsicle/commands/list.rb
opsicle-2.10.1 lib/opsicle/commands/list.rb
opsicle-2.10.0 lib/opsicle/commands/list.rb
opsicle-2.9.6 lib/opsicle/commands/list.rb
opsicle-2.9.4 lib/opsicle/commands/list.rb
opsicle-2.9.3 lib/opsicle/commands/list.rb
opsicle-2.9.2 lib/opsicle/commands/list.rb