Class: NeetoDeploy::CLI::Buildpacks::List

Inherits:
NeetoDeploy::CLI::Base show all
Includes:
Session
Defined in:
lib/neeto_deploy/cli/buildpacks/list.rb

Constant Summary

Constants included from Session

Session::CONSOLE_EXECUTABLE

Instance Attribute Summary collapse

Attributes inherited from NeetoDeploy::CLI::Base

#ui

Instance Method Summary collapse

Methods included from Session

#auth_headers, #console_executable_name, #json_auth_headers, #os, require_app_option, #send_delete_request, #send_get_request, #send_patch_request, #send_post_request

Methods inherited from NeetoDeploy::CLI::Base

#create_config_dir

Constructor Details

#initialize(options:) ⇒ List

Returns a new instance of List.



14
15
16
17
# File 'lib/neeto_deploy/cli/buildpacks/list.rb', line 14

def initialize(options:)
  super()
  @app_slug = options[:app]
end

Instance Attribute Details

#app_slugObject (readonly)

Returns the value of attribute app_slug.



12
13
14
# File 'lib/neeto_deploy/cli/buildpacks/list.rb', line 12

def app_slug
  @app_slug
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/neeto_deploy/cli/buildpacks/list.rb', line 19

def run
  ui.execute_with_loading("Fetching buildpacks...") do
    @response = send_get_request("#{NEETO_DEPLOY_CLI_API_BASE_URL}/buildpacks", { app_slug: })
  end

  return ui.error(@response["error"] || @response.message) unless @response.success?

  buildpacks = JSON.parse(@response.body)["buildpacks"]

  if buildpacks.nil? || buildpacks.empty?
    ui.info("No buildpacks found for #{app_slug}.")
    return
  end

  rows = buildpacks.map { |b| [b["position"], b["url"]] }
  table = Terminal::Table.new(headings: ["Position", "Buildpack"], rows: rows)
  ui.info(table)
end