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.9.0 lib/opsicle/commands/list.rb
opsicle-2.8.0 lib/opsicle/commands/list.rb
opsicle-2.6.0 lib/opsicle/commands/list.rb
opsicle-2.5.0 lib/opsicle/commands/list.rb
opsicle-2.4.1 lib/opsicle/commands/list.rb
opsicle-2.4.0 lib/opsicle/commands/list.rb
opsicle-2.3.1 lib/opsicle/commands/list.rb
opsicle-2.3.0 lib/opsicle/commands/list.rb
opsicle-2.2.1 lib/opsicle/commands/list.rb
opsicle-2.2.0 lib/opsicle/commands/list.rb
opsicle-2.1.0 lib/opsicle/commands/list.rb
opsicle-2.0.2 lib/opsicle/commands/list.rb
opsicle-2.0.1 lib/opsicle/commands/list.rb
opsicle-2.0.0 lib/opsicle/commands/list.rb
opsicle-1.1.1 lib/opsicle/commands/list.rb
opsicle-1.1.0 lib/opsicle/commands/list.rb
opsicle-1.0.1 lib/opsicle/commands/list.rb
opsicle-0.18.1 lib/opsicle/commands/list.rb
opsicle-0.18.0 lib/opsicle/commands/list.rb
opsicle-0.16.0 lib/opsicle/commands/list.rb