Class: Cask::Artifact::Installer Private

Inherits:
AbstractArtifact show all
Defined in:
cask/artifact/installer.rb

Overview

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.

Artifact corresponding to the installer stanza.

Constant Summary collapse

VALID_KEYS =

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.

T.let(Set.new([
  :manual,
  :script,
]).freeze, T::Set[Symbol])

Constants inherited from AbstractArtifact

AbstractArtifact::DirectivesType

Instance Attribute Summary collapse

Attributes inherited from AbstractArtifact

#cask

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractArtifact

#cask_sandbox, #config, dirmethod, dsl_key, english_article, english_name, read_script_arguments, #run_cask_sandbox, #sort_order, #staged_path_join_executable, #to_args

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_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

#initialize(cask, **args) ⇒ 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.

Parameters:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'cask/artifact/installer.rb', line 90

def initialize(cask, **args)
  super

  if args.key?(:manual)
    manual = args[:manual]
    if !manual.is_a?(String) && !manual.is_a?(Pathname)
      raise CaskInvalidError.new(cask, "#{self.class.dsl_key} requires a path for :manual")
    end

    @path = T.let(Pathname(manual), Pathname)
    @args = T.let({}, T::Hash[Symbol, T.untyped])
    @manual_install = T.let(true, T::Boolean)
  else
    script_path, script_args = self.class.read_script_arguments(
      args[:script], self.class.dsl_key.to_s, { must_succeed: true, sudo: false }, print_stdout: true
    )
    raise CaskInvalidError.new(cask, "#{self.class.dsl_key} missing executable") if script_path.nil?

    @path = T.let(Pathname(script_path), Pathname)
    @args = T.let(script_args, T::Hash[Symbol, T.untyped])
    @manual_install = T.let(false, T::Boolean)
  end
end

Instance Attribute Details

#args ⇒ Hash{Symbol => T.untyped} (readonly)

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:



81
82
83
# File 'cask/artifact/installer.rb', line 81

def args
  @args
end

#manual_install ⇒ Boolean (readonly)

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)


84
85
86
# File 'cask/artifact/installer.rb', line 84

def manual_install
  @manual_install
end

#path ⇒ Pathname (readonly)

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:



78
79
80
# File 'cask/artifact/installer.rb', line 78

def path
  @path
end

Class Method Details

.from_args(cask, **args) ⇒ T.attached_class

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.

The stanza arguments are validated below rather than typed as keywords so that an unknown key names itself in the error.

Parameters:

Returns:

  • (T.attached_class)

Raises:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'cask/artifact/installer.rb', line 53

def self.from_args(cask, **args)
  raise CaskInvalidError.new(cask, "'installer' stanza requires an argument.") if args.empty?

  if args.key?(:script) && !args[:script].respond_to?(:key?)
    if args.key?(:executable)
      raise CaskInvalidError.new(cask, "'installer' stanza gave arguments for both :script and :executable.")
    end

    args[:executable] = args[:script]
    args.delete(:script)
    args = { script: args }
  end

  if args.keys.count != 1
    raise CaskInvalidError.new(
      cask,
      "invalid 'installer' stanza: Only one of #{VALID_KEYS.inspect} is permitted.",
    )
  end

  ::Utils::Data.assert_valid_keys(args, *VALID_KEYS)
  new(cask, **args)
end

Instance Method Details

#install_phase(adopt: false, auto_updates: false, force: false, verbose: false, predecessor: nil, command: SystemCommand) ⇒ 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.

Parameters:

  • adopt (Boolean) (defaults to: false)
  • auto_updates (Boolean, nil) (defaults to: false)
  • force (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • predecessor (Cask, nil) (defaults to: nil)
  • command (T.class_of(SystemCommand)) (defaults to: SystemCommand)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'cask/artifact/installer.rb', line 28

def install_phase(adopt: false, auto_updates: false, force: false, verbose: false, predecessor: nil,
                  command: SystemCommand)
  if manual_install
    puts <<~EOS
      Cask #{cask} only provides a manual installer. To run it and complete the installation:
        open #{cask.staged_path.join(path).to_s.shellescape}
    EOS
  else
    ohai "Running #{self.class.dsl_key} script '#{path}'"

    executable_path = staged_path_join_executable(path)

    command.run!(
      executable_path,
      **args,
      env: { "PATH" => PATH.new(
        HOMEBREW_PREFIX/"bin", HOMEBREW_PREFIX/"sbin", ENV.fetch("PATH")
      ) },
    )
  end
end

#requires_sudo? ⇒ 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)


87
# File 'cask/artifact/installer.rb', line 87

def requires_sudo? = args[:sudo] == true

#summarize ⇒ 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:



115
# File 'cask/artifact/installer.rb', line 115

def summarize = path.to_s

#to_h ⇒ Hash{Symbol => T.untyped}

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:



118
119
120
121
122
# File 'cask/artifact/installer.rb', line 118

def to_h
  { path: }.tap do |h|
    h[:args] = args unless manual_install
  end
end