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.

Constant Summary collapse

PACKAGE_TYPE =

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

:krew
PACKAGE_TYPE_NAME =

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

"Krew Plugin"
"Krew plugins"

Class Method Summary collapse

Methods inherited from Extension

add_supported?, banner_name, check, check_label, cleanup!, cleanup_heading, cleanup_items, cleanup_supported?, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_entry, dump_name, dump_output, dump_supported?, dump_with, entry, #failure_reason, fetchable_name, flag, inherited, install!, install_supported?, install_verb, #installed_and_up_to_date?, legacy_check_step, package_description, package_installed?, package_manager_env, package_manager_name, package_record, predicate_method, preinstall!, quote, remove_supported?, switch_description, type

Methods inherited from PackageType

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

Class Method Details

.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)


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

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

  kubectl = package_manager_executable
  return false if kubectl.nil?

  with_env(package_manager_env(kubectl)) do
    Bundle.system(kubectl.to_s, "krew", "install", name, verbose:)
  end
end

.installed_packagesArray<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:



75
76
77
78
79
80
# File 'bundle/extensions/krew.rb', line 75

def installed_packages
  installed_packages = @installed_packages
  return installed_packages if installed_packages

  @installed_packages = packages.dup
end

.package_manager_executablePathname?

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:



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

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

.package_manager_installed?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.

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'bundle/extensions/krew.rb', line 28

def package_manager_installed?
  return @krew_installed unless @krew_installed.nil?

  kubectl = package_manager_executable
  result = if kubectl.present?
    Kernel.system(package_manager_env(kubectl), kubectl.to_s, "krew", "version",
                  out: File::NULL, err: File::NULL) == true
  else
    false
  end
  @krew_installed = T.let(result, T.nilable(T::Boolean))
  result
end

.packagesArray<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:



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

def packages
  packages = @packages
  return packages if packages

  kubectl = package_manager_executable
  @packages = if package_manager_installed? && kubectl
    output = with_env(package_manager_env(kubectl)) { `#{kubectl} krew list 2>/dev/null` }
    parse_plugin_list(output)
  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:



83
84
85
86
87
88
89
90
91
# File 'bundle/extensions/krew.rb', line 83

def parse_plugin_list(output)
  output.lines.filter_map do |line|
    line = line.strip
    next if line.empty?

    name = line.split(/\s+/).first
    name.presence
  end.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.



15
16
17
18
19
20
# File 'bundle/extensions/krew.rb', line 15

def reset!
  @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))
  @krew_installed = T.let(nil, T.nilable(T::Boolean))
end