Class: Deploio::Commands::Apps

Inherits:
Thor
  • Object
show all
Includes:
SharedOptions
Defined in:
lib/deploio/commands/apps.rb

Instance Method Summary collapse

Methods included from SharedOptions

included

Instance Method Details

#infoObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/deploio/commands/apps.rb', line 71

def info
  setup_options
  app_ref = resolve_app
  data = @nctl.get_app(app_ref)

  if options[:json]
    puts JSON.pretty_generate(data)
    return
  end

  display_app_info(data, app_ref)
end

#listObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/deploio/commands/apps.rb', line 21

def list
  setup_options
  project = merged_options[:project] ? resolve_project(merged_options[:project]) : nil
  raw_apps = project ? @nctl.get_apps_by_project(project) : @nctl.get_all_apps

  if options[:json]
    puts JSON.pretty_generate(raw_apps)
    return
  end

  if raw_apps.empty?
    msg = project ? "No apps found in project #{merged_options[:project]}" : "No apps found"
    Output.warning(msg) unless merged_options[:dry_run]
    return
  end

  resolver = AppResolver.new(nctl_client: @nctl)
  show_price = merged_options[:chf]
  price_fetcher = PriceFetcher.new if show_price

  rows = raw_apps.map do |app|
     = app["metadata"] || {}
    spec = app["spec"] || {}
    for_provider = spec["forProvider"] || {}
    git = for_provider["git"] || {}
    config = for_provider["config"] || {}
    namespace = ["namespace"] || ""
    name = ["name"] || ""

    row = [
      resolver.short_name_for(namespace, name),
      project_from_namespace(namespace, resolver.current_org),
      presence(config["size"], default: "micro"),
      presence(git["revision"])
    ]

    if show_price
      price = price_fetcher.price_for_app(app)
      row << price_fetcher.format_price(price)
    end

    row
  end

  headers = %w[APP PROJECT SIZE REVISION]
  headers << "PRICE" if show_price
  Output.table(rows, headers: headers)
end