Class: Cask::Artifact::CommandWrapper Private

Inherits:
Binary show all
Defined in:
cask/artifact/command_wrapper.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 command_wrapper stanza.

Constant Summary collapse

Arguments =

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.type_alias { T.any(String, Pathname, T::Array[T.any(String, Pathname)]) }
Environment =

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.type_alias { T::Hash[T.any(String, Symbol), T.any(String, Pathname)] }

Constants inherited from AbstractArtifact

AbstractArtifact::DirectivesType

Instance Attribute Summary

Attributes inherited from AbstractArtifact

#cask

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Binary

#link

Methods inherited from Symlinked

english_description, #link_action, link_type_english_name, #summarize_installed, #target_links_to_source?, #uninstall_phase

Methods included from OS::Mac::Cask::Artifact::Symlinked

#create_filesystem_link

Methods inherited from Relocated

#add_altname_metadata, #resolve_target, #source, #summarize, #target, #to_a

Methods included from OS::Linux::Cask::Artifact::Relocated

#add_altname_metadata

Methods inherited from AbstractArtifact

#cask_sandbox, #config, dsl_key, english_article, english_name, read_script_arguments, #requires_sudo?, #run_cask_sandbox, #sort_order, #staged_path_join_executable, #summarize

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, name, content: nil, executable: nil, args: [], env: {}) ⇒ 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:



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

def initialize(cask, name, content: nil, executable: nil, args: [], env: {})
  name = Pathname(name)
  if name.basename != name || [".", ".."].include?(name.to_s)
    raise CaskInvalidError.new(cask, "'command_wrapper' requires a command name without path components")
  end
  if content.blank? && executable.to_s.blank?
    raise CaskInvalidError.new(cask, "'command_wrapper' requires content or executable")
  end
  if content.present? && executable.to_s.present?
    raise CaskInvalidError.new(cask, "'command_wrapper' requires content or executable, not both")
  end
  if content.present? && (args.present? || env.present?)
    raise CaskInvalidError.new(cask, "'command_wrapper' args and env require executable")
  end

  super(cask, ".homebrew-command-wrappers/#{name}", target: name)
  @content = T.let(content.presence, T.nilable(String))
  @executable = T.let(executable&.to_s.presence, T.nilable(String))
  @args = T.let(Array(args).map(&:to_s), T::Array[String])
  @env = T.let(env.to_h { |key, value| [key.to_s, value.to_s] }, T::Hash[String, String])
end

Class Method Details

.dirmethod ⇒ 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:



18
# File 'cask/artifact/command_wrapper.rb', line 18

def self.dirmethod = :binarydir

.from_args(cask, name, options = nil) ⇒ 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.

Parameters:

Returns:

  • (T.attached_class)

Raises:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'cask/artifact/command_wrapper.rb', line 27

def self.from_args(cask, name, options = nil)
  options = {} if options.nil?
  raise CaskInvalidError.new(cask, "'command_wrapper' requires a hash of options") unless options.is_a?(Hash)

  ::Utils::Data.assert_valid_keys(options, :content, :executable, :args, :env)

  new(
    cask,
    name,
    content:    options[:content],
    executable: options[:executable],
    args:       options.fetch(:args, []),
    env:        options.fetch(:env, {}),
  )
end

Instance Method Details

#install_phase(adopt: false, auto_updates: false, force: false, verbose: false, predecessor: nil, overwrite: false, dry_run: false, 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)
  • overwrite (Boolean) (defaults to: false)
  • dry_run (Boolean) (defaults to: false)
  • command (T.class_of(SystemCommand)) (defaults to: SystemCommand)


87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'cask/artifact/command_wrapper.rb', line 87

def install_phase(adopt: false, auto_updates: false, force: false, verbose: false, predecessor: nil,
                  overwrite: false, dry_run: false, command: SystemCommand)
  unless dry_run
    if (content = @content)
      source.dirname.mkpath
      source.write(content)
    elsif (executable = @executable)
      args = @args.map { |arg| Shellwords.shellescape(arg) }
      source.write_env_script(executable, args, @env)
    end
  end
  super
end

#to_args ⇒ Array<T.anything>

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:



102
103
104
105
106
107
108
109
110
111
112
# File 'cask/artifact/command_wrapper.rb', line 102

def to_args
  options = {}
  if (content = @content)
    options[:content] = content
  else
    options[:executable] = @executable
    options[:args] = @args if @args.present?
    options[:env] = @env if @env.present?
  end
  [@target_string, options]
end