Class: Envirobly::Defaults::Account

Inherits:
Envirobly::Default show all
Includes:
Colorize
Defined in:
lib/envirobly/defaults/account.rb

Constant Summary

Constants included from Colorize

Colorize::BLUE, Colorize::BOLD, Colorize::FAINT, Colorize::GREEN, Colorize::RED, Colorize::RESET, Colorize::YELLOW

Instance Attribute Summary

Attributes inherited from Envirobly::Default

#shell

Instance Method Summary collapse

Methods included from Colorize

#bold, #cross, #display_config_errors, #downwards_arrow_to_right, #faint, #green, #green_check, #red, #yellow

Methods inherited from Envirobly::Default

#initialize, #require_if_none, #save, #save_if_none, #value

Constructor Details

This class inherits a constructor from Envirobly::Default

Instance Method Details

#require_valueObject



6
7
8
9
10
11
12
13
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
# File 'lib/envirobly/defaults/account.rb', line 6

def require_value
  api = Envirobly::Api.new
  accounts = api.list_accounts

  if accounts.object.blank?
    shell.say_error "Please connect an AWS account to your Envirobly account first."
    exit 1
  end

  # If only one account exists, it will be used
  id = accounts.object.first.fetch("id")

  if accounts.object.size > 1
    puts "Choose default account to deploy this project to:"

    data = [ [ "ID", "Name", "AWS number", "URL" ] ] +
      accounts.object.pluck("id", "name", "aws_id", "url")

    shell.print_table data, borders: true

    limited_to = accounts.object.pluck("id").map(&:to_s)

    begin
      id = shell.ask("Type in the account ID:", limited_to:).to_i
    rescue Interrupt
      shell.say_error "Cancelled"
      exit
    end
  end

  save id

  shell.say "Account ##{id} set as project default "
  shell.say green_check

  id
end