Class: Cask::Artifact::CommandWrapper Private
- Inherits:
-
Binary
- Object
- AbstractArtifact
- Relocated
- Symlinked
- Binary
- Cask::Artifact::CommandWrapper
- 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
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(cask, name, content: nil, executable: nil, args: [], env: {}) ⇒ void constructor private
- #install_phase(force: false, adopt: false, command: SystemCommand, **options) ⇒ void private
- #to_args ⇒ Array<T.anything> private
Methods inherited from Binary
Methods inherited from Symlinked
english_description, link_type_english_name, #summarize_installed, #uninstall_phase
Methods included from OS::Mac::Cask::Artifact::Symlinked
Methods inherited from Relocated
#add_altname_metadata, #resolve_target, #source, #summarize, #target, #to_a
Methods included from OS::Linux::Cask::Artifact::Relocated
Methods inherited from AbstractArtifact
#cask_sandbox, #config, dsl_key, english_article, english_name, read_script_arguments, #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_outside_github_actions, #opoo_without_github_actions_annotation, #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.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'cask/artifact/command_wrapper.rb', line 42 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.
16 |
# File 'cask/artifact/command_wrapper.rb', line 16 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.
25 26 27 28 29 30 |
# File 'cask/artifact/command_wrapper.rb', line 25 def self.from_args(cask, name, = nil) ||= {} .assert_valid_keys(:content, :executable, :args, :env) new(cask, name, **) end |
Instance Method Details
#install_phase(force: false, adopt: false, command: SystemCommand, **options) ⇒ 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.
72 73 74 75 76 77 78 79 80 81 |
# File 'cask/artifact/command_wrapper.rb', line 72 def install_phase(force: false, adopt: false, command: SystemCommand, **) 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 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.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'cask/artifact/command_wrapper.rb', line 84 def to_args = {} if (content = @content) [:content] = content else [:executable] = @executable [:args] = @args if @args.present? [:env] = @env if @env.present? end [@target_string, ] end |