Module: HomebrewArgvExtension

Defined in:
brew/Library/Homebrew/extend/ARGV.rb

Instance Method Summary collapse

Instance Method Details

#bottle_archObject



146
147
148
149
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 146

def bottle_arch
  arch = value "bottle-arch"
  arch&.to_sym
end

#build_bottle?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 142

def build_bottle?
  include?("--build-bottle") || !ENV["HOMEBREW_BUILD_BOTTLE"].nil?
end

#build_formula_from_source?(f) ⇒ Boolean

Whether a given formula should be built from source during the current installation run.

Returns:

  • (Boolean)


157
158
159
160
161
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 157

def build_formula_from_source?(f)
  return false if !build_from_source? && !build_bottle?

  formulae.any? { |argv_f| argv_f.full_name == f.full_name }
end

#build_from_source?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 151

def build_from_source?
  switch?("s") || include?("--build-from-source")
end

#build_stable?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 134

def build_stable?
  !(include?("--HEAD") || include?("--devel"))
end

#build_universal?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 138

def build_universal?
  include? "--universal"
end

#casksObject



37
38
39
40
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 37

def casks
  # TODO: use @instance variable to ||= cache when moving to CLI::Parser
  downcased_unique_named.grep HOMEBREW_CASK_TAP_CASK_REGEX
end

#ccObject



175
176
177
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 175

def cc
  value "cc"
end

#collect_build_flagsObject

If the user passes any flags that trigger building over installing from a bottle, they are collected here and returned as an Array for checking.



185
186
187
188
189
190
191
192
193
194
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 185

def collect_build_flags
  build_flags = []

  build_flags << "--HEAD" if include?("--HEAD")
  build_flags << "--universal" if build_universal?
  build_flags << "--build-bottle" if build_bottle?
  build_flags << "--build-from-source" if build_from_source?

  build_flags
end

#debug?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 102

def debug?
  flag?("--debug") || !ENV["HOMEBREW_DEBUG"].nil?
end

#envObject



179
180
181
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 179

def env
  value "env"
end

#fetch_head?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 171

def fetch_head?
  include? "--fetch-HEAD"
end

#flag?(flag) ⇒ Boolean

Returns:

  • (Boolean)


163
164
165
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 163

def flag?(flag)
  options_only.include?(flag) || switch?(flag[2, 1])
end

#flags_onlyObject



13
14
15
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 13

def flags_only
  select { |arg| arg.start_with?("--") }
end

#force?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 94

def force?
  flag? "--force"
end

#force_bottle?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 167

def force_bottle?
  include?("--force-bottle")
end

#formulaeObject



17
18
19
20
21
22
23
24
25
26
27
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 17

def formulae
  require "formula"
  # TODO: use @instance variable to ||= cache when moving to CLI::Parser
  (downcased_unique_named - casks).map do |name|
    if name.include?("/") || File.exist?(name)
      Formulary.factory(name, spec)
    else
      Formulary.find_with_priority(name, spec)
    end
  end.uniq(&:name)
end

#git?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 118

def git?
  flag? "--git"
end

#homebrew_developer?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 122

def homebrew_developer?
  !ENV["HOMEBREW_DEVELOPER"].nil?
end

#ignore_deps?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 130

def ignore_deps?
  include? "--ignore-dependencies"
end

#interactive?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 110

def interactive?
  flag? "--interactive"
end

#keep_tmp?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 114

def keep_tmp?
  include? "--keep-tmp"
end

#kegsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 42

def kegs
  require "keg"
  require "formula"
  # TODO: use @instance variable to ||= cache when moving to CLI::Parser
  downcased_unique_named.map do |name|
    raise UsageError if name.empty?

    rack = Formulary.to_rack(name.downcase)

    dirs = rack.directory? ? rack.subdirs : []

    raise NoSuchKegError, rack.basename if dirs.empty?

    linked_keg_ref = HOMEBREW_LINKED_KEGS/rack.basename
    opt_prefix = HOMEBREW_PREFIX/"opt/#{rack.basename}"

    begin
      if opt_prefix.symlink? && opt_prefix.directory?
        Keg.new(opt_prefix.resolved_path)
      elsif linked_keg_ref.symlink? && linked_keg_ref.directory?
        Keg.new(linked_keg_ref.resolved_path)
      elsif dirs.length == 1
        Keg.new(dirs.first)
      else
        f = if name.include?("/") || File.exist?(name)
          Formulary.factory(name)
        else
          Formulary.from_rack(rack)
        end

        unless (prefix = f.installed_prefix).directory?
          raise MultipleVersionsInstalledError, rack.basename
        end

        Keg.new(prefix)
      end
    rescue FormulaUnavailableError
      raise <<~EOS
        Multiple kegs installed to #{rack}
        However we don't know which one you refer to.
        Please delete (with rm -rf!) all but one and then try again.
      EOS
    end
  end
end

#namedObject



4
5
6
7
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 4

def named
  # TODO: use @instance variable to ||= cache when moving to CLI::Parser
  self - options_only
end

#no_sandbox?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 126

def no_sandbox?
  include?("--no-sandbox") || !ENV["HOMEBREW_NO_SANDBOX"].nil?
end

#options_onlyObject



9
10
11
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 9

def options_only
  select { |arg| arg.start_with?("-") }
end

#quieter?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 106

def quieter?
  flag? "--quieter"
end

#resolved_formulaeObject



29
30
31
32
33
34
35
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 29

def resolved_formulae
  require "formula"
  # TODO: use @instance variable to ||= cache when moving to CLI::Parser
  (downcased_unique_named - casks).map do |name|
    Formulary.resolve(name, spec: spec(nil))
  end.uniq(&:name)
end

#value(name) ⇒ Object



88
89
90
91
92
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 88

def value(name)
  arg_prefix = "--#{name}="
  flag_with_value = find { |arg| arg.start_with?(arg_prefix) }
  flag_with_value&.delete_prefix(arg_prefix)
end

#verbose?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 98

def verbose?
  flag?("--verbose") || !ENV["VERBOSE"].nil? || !ENV["HOMEBREW_VERBOSE"].nil?
end