Class: HerokuAppInfo::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku_app_info/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:) ⇒ Cli



8
9
10
# File 'lib/heroku_app_info/cli.rb', line 8

def initialize(root:)
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



11
12
13
# File 'lib/heroku_app_info/cli.rb', line 11

def root
  @root
end

Instance Method Details

#dump_app_and_pg_details(apps) ⇒ Object

dump each app and pg info



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/heroku_app_info/cli.rb', line 52

def dump_app_and_pg_details(apps)
  writer = Writer.new(@options)

  apps.each { |app|
    raw_app = @fetcher.app(app)
    writer.write(app, raw_app) if @options.raw_output?
    app_info = @parser.parse(raw_app)
    if has_pg?(app_info)
      raw_db = @fetcher.pg(app)
      writer.write(app, raw_db, sort: "pg") if @options.raw_output?
      db_info = @parser.parse(raw_db)
      writer.write(app, db_info, sort: "pg")
    end
    writer.write(app, app_info)
  }
end

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/heroku_app_info/cli.rb', line 13

def execute
  @options = Options.new(ARGV.dup)

  set_authz! if @options.authz

  @fetcher = Fetcher.new(@options)
  @parser = Parser.new
  if @options.show_all?
    show_all_apps
  else
    apps =
      if @options.apps.nil?
        @parser.apps(@fetcher.all_apps)
      else
        @options.apps
      end
    dump_app_and_pg_details(apps)
  end
end

#has_pg?(app_info) ⇒ Boolean



73
74
75
# File 'lib/heroku_app_info/cli.rb', line 73

def has_pg?(app_info)
  app_info.has_key?("Addons") && app_info["Addons"].grep(/postgresql/).size > 0
end

#set_authz!Object

set API KEY to Environment Variable

Currently, Heroku Account require MFA, so the login and password method is not supported



38
39
40
# File 'lib/heroku_app_info/cli.rb', line 38

def set_authz!
  ENV["HEROKU_API_KEY"] = @options.authz
end

#show_all_appsObject

show all apps



45
46
47
# File 'lib/heroku_app_info/cli.rb', line 45

def show_all_apps
  puts @fetcher.all_apps
end