Class: Homebrew::Bundle::Krew Private

Inherits:
Extension show all
Defined in:
bundle/extensions/krew.rb

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Class Method Summary collapse

Methods inherited from Extension

add_supported?, check, cleanup!, cleanup_disable_description, cleanup_disable_env, cleanup_item_name, cleanup_items, cleanup_supported?, disable_predicate_method, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_entry, dump_name, dump_output, dump_supported?, dump_with, ensure_package_manager_installed!, entry, #failure_reason, flag, inherited, install!, install_supported?, install_verb, #installed_and_up_to_date?, legacy_check_step, package_description, package_installed?, package_manager_executable!, package_manager_installed?, package_manager_name, package_record, predicate_method, preinstall!, quote, remove_supported?, switch_description, with_package_manager_env

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods inherited from PackageType

batch_installable?, check, #checkable_entries, dump, dump_output, dump_supported?, #exit_early_check, #failure_reason, #find_actionable, #format_checkable, #full_check, inherited, install!, install_batch!, install_supported?, install_verb, #installed_and_up_to_date?, preinstall!

Class Method Details

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



18
# File 'bundle/extensions/krew.rb', line 18

def banner_name = "Krew plugins"

.check_label ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



15
# File 'bundle/extensions/krew.rb', line 15

def check_label = "Krew Plugin"

.cleanup_heading ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



29
30
31
# File 'bundle/extensions/krew.rb', line 29

def cleanup_heading
  banner_name
end

.install_package!(name, with: nil, verbose: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • name (String)
  • with (Array<String>, nil) (defaults to: nil)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'bundle/extensions/krew.rb', line 64

def install_package!(name, with: nil, verbose: false)
  _ = with

  with_package_manager_env do |krew|
    Bundle.system(krew.to_s, package_installed?(name) ? "upgrade" : "install", name, verbose:)
  end
end

.installed_packages ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



73
74
75
# File 'bundle/extensions/krew.rb', line 73

def installed_packages
  @installed_packages ||= packages.dup
end

.package_manager_env(executable) ⇒ Hash{String => String}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



39
40
41
# File 'bundle/extensions/krew.rb', line 39

def package_manager_env(executable)
  { "PATH" => "#{executable.dirname}:#{ORIGINAL_PATHS.join(":")}" }
end

.package_manager_executable ⇒ Pathname?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



34
35
36
# File 'bundle/extensions/krew.rb', line 34

def package_manager_executable
  @package_manager_executable ||= T.let(which("kubectl-krew", ORIGINAL_PATHS), T.nilable(Pathname))
end

.package_outdated?(name, with: nil, source: nil) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'bundle/extensions/krew.rb', line 80

def package_outdated?(name, with: nil, source: nil)
  with_package_manager_env do |krew|
    unless @indexes_updated
      command_output(krew, args: ["update"])
      @indexes_updated = true
    end

    receipt = YAML.safe_load_file(File.join(ENV["KREW_ROOT"].presence || "#{Dir.home}/.krew",
                                            "receipts", "#{Pathname.new(name).basename}.yaml"))
    spec = receipt["spec"] if receipt.is_a?(Hash)
    installed = spec["version"] if spec.is_a?(Hash)
    latest = command_output(krew, args: ["info", name])[/^VERSION: (\S+)$/, 1]
    if !installed.is_a?(String) || installed.blank? || latest.blank?
      raise "Invalid Krew version for #{name}"
    end

    Version.new(latest) > Version.new(installed)
  end
end

.packages ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
# File 'bundle/extensions/krew.rb', line 44

def packages
  packages = @packages
  return packages if packages

  @packages = if package_manager_installed?
    with_package_manager_env do |krew|
      parse_plugin_list(command_output(krew, args: ["list"]))
    end
  else
    []
  end
end

.parse_plugin_list(output) ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



101
102
103
104
105
106
107
108
109
# File 'bundle/extensions/krew.rb', line 101

def parse_plugin_list(output)
  # Krew prints only plugin names when stdout is piped.
  names = output.each_line(chomp: true).reject(&:empty?)
  if names.any? { |name| name.match?(/[[:space:]]/) }
    raise "Invalid Krew inventory: plugin names cannot contain whitespace"
  end

  names.uniq
end

.reset! ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



21
22
23
24
25
26
# File 'bundle/extensions/krew.rb', line 21

def reset!
  @indexes_updated = T.let(nil, T.nilable(T::Boolean))
  @packages = T.let(nil, T.nilable(T::Array[String]))
  @installed_packages = T.let(nil, T.nilable(T::Array[String]))
  @package_manager_executable = T.let(nil, T.nilable(Pathname))
end

.type ⇒ Symbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



12
# File 'bundle/extensions/krew.rb', line 12

def type = :krew

.uninstall_package!(name, executable: Pathname.new("")) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


113
114
115
# File 'bundle/extensions/krew.rb', line 113

def uninstall_package!(name, executable: Pathname.new(""))
  Bundle.system(executable.to_s, "uninstall", name, verbose: false)
end