Module: HomebrewArgvExtension

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

Instance Method Summary collapse

Instance Method Details

#bottle_archObject



237
238
239
240
# File 'Library/Homebrew/extend/ARGV.rb', line 237

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

#build_all_from_source?Boolean

Returns:

  • (Boolean)


246
247
248
# File 'Library/Homebrew/extend/ARGV.rb', line 246

def build_all_from_source?
  !ENV["HOMEBREW_BUILD_FROM_SOURCE"].nil?
end

#build_bottle?Boolean

Returns:

  • (Boolean)


233
234
235
# File 'Library/Homebrew/extend/ARGV.rb', line 233

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

#build_devel?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'Library/Homebrew/extend/ARGV.rb', line 221

def build_devel?
  include? "--devel"
end

#build_formula_from_source?(f) ⇒ Boolean

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

Returns:

  • (Boolean)


252
253
254
255
256
# File 'Library/Homebrew/extend/ARGV.rb', line 252

def build_formula_from_source?(f)
  return true if build_all_from_source?
  return false unless build_from_source? || build_bottle?
  formulae.any? { |argv_f| argv_f.full_name == f.full_name }
end

#build_from_source?Boolean

Returns:

  • (Boolean)


242
243
244
# File 'Library/Homebrew/extend/ARGV.rb', line 242

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

#build_head?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'Library/Homebrew/extend/ARGV.rb', line 217

def build_head?
  include? "--HEAD"
end

#build_stable?Boolean

Returns:

  • (Boolean)


225
226
227
# File 'Library/Homebrew/extend/ARGV.rb', line 225

def build_stable?
  !(build_head? || build_devel?)
end

#build_universal?Boolean

Returns:

  • (Boolean)


229
230
231
# File 'Library/Homebrew/extend/ARGV.rb', line 229

def build_universal?
  include? "--universal"
end

#casksObject



87
88
89
# File 'Library/Homebrew/extend/ARGV.rb', line 87

def casks
  @casks ||= downcased_unique_named.grep HOMEBREW_CASK_TAP_CASK_REGEX
end

#ccObject



276
277
278
# File 'Library/Homebrew/extend/ARGV.rb', line 276

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.



286
287
288
289
290
291
292
293
294
295
# File 'Library/Homebrew/extend/ARGV.rb', line 286

def collect_build_flags
  build_flags = []

  build_flags << "--HEAD" if build_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)


165
166
167
# File 'Library/Homebrew/extend/ARGV.rb', line 165

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

#dry_run?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'Library/Homebrew/extend/ARGV.rb', line 181

def dry_run?
  include?("--dry-run") || switch?("n")
end

#envObject



280
281
282
# File 'Library/Homebrew/extend/ARGV.rb', line 280

def env
  value "env"
end

#fetch_head?Boolean

Returns:

  • (Boolean)


266
267
268
# File 'Library/Homebrew/extend/ARGV.rb', line 266

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

#flag?(flag) ⇒ Boolean

Returns:

  • (Boolean)


258
259
260
# File 'Library/Homebrew/extend/ARGV.rb', line 258

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

#flags_onlyObject



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

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

#force?Boolean

Returns:

  • (Boolean)


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

def force?
  flag? "--force"
end

#force_bottle?Boolean

Returns:

  • (Boolean)


262
263
264
# File 'Library/Homebrew/extend/ARGV.rb', line 262

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

#formula_install_option_namesObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'Library/Homebrew/extend/ARGV.rb', line 2

def formula_install_option_names
  %w[
    --debug
    --env=
    --ignore-dependencies
    --cc=
    --build-from-source
    --devel
    --HEAD
    --keep-tmp
    --interactive
    --git
    --sandbox
    --no-sandbox
    --build-bottle
    --force-bottle
    --verbose
    --force
    -i
    -v
    -d
    -g
    -s
    -f
  ].freeze
end

#formulaeObject



41
42
43
44
45
46
47
48
49
50
# File 'Library/Homebrew/extend/ARGV.rb', line 41

def formulae
  require "formula"
  @formulae ||= (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)


189
190
191
# File 'Library/Homebrew/extend/ARGV.rb', line 189

def git?
  flag? "--git"
end

#homebrew_developer?Boolean

Returns:

  • (Boolean)


193
194
195
# File 'Library/Homebrew/extend/ARGV.rb', line 193

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

#ignore_deps?Boolean

Returns:

  • (Boolean)


205
206
207
# File 'Library/Homebrew/extend/ARGV.rb', line 205

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

#include?(arg) ⇒ Boolean

Returns:

  • (Boolean)


136
137
138
# File 'Library/Homebrew/extend/ARGV.rb', line 136

def include?(arg)
  !(@n = index(arg)).nil?
end

#interactive?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'Library/Homebrew/extend/ARGV.rb', line 173

def interactive?
  flag? "--interactive"
end

#jsonObject



213
214
215
# File 'Library/Homebrew/extend/ARGV.rb', line 213

def json
  value "json"
end

#keep_tmp?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'Library/Homebrew/extend/ARGV.rb', line 185

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

#kegsObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'Library/Homebrew/extend/ARGV.rb', line 91

def kegs
  require "keg"
  require "formula"
  @kegs ||= downcased_unique_named.collect 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.undent
        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



29
30
31
# File 'Library/Homebrew/extend/ARGV.rb', line 29

def named
  @named ||= self - options_only
end

#nextObject



140
141
142
# File 'Library/Homebrew/extend/ARGV.rb', line 140

def next
  at(@n + 1) || raise(UsageError)
end

#no_sandbox?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'Library/Homebrew/extend/ARGV.rb', line 201

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

#one?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'Library/Homebrew/extend/ARGV.rb', line 177

def one?
  flag? "--1"
end

#only_deps?Boolean

Returns:

  • (Boolean)


209
210
211
# File 'Library/Homebrew/extend/ARGV.rb', line 209

def only_deps?
  include? "--only-dependencies"
end

#options_onlyObject



33
34
35
# File 'Library/Homebrew/extend/ARGV.rb', line 33

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

#quieter?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'Library/Homebrew/extend/ARGV.rb', line 169

def quieter?
  flag? "--quieter"
end

#resolved_formulaeObject



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
# File 'Library/Homebrew/extend/ARGV.rb', line 52

def resolved_formulae
  require "formula"
  @resolved_formulae ||= (downcased_unique_named - casks).map do |name|
    if name.include?("/") || File.exist?(name)
      f = Formulary.factory(name, spec)
      if f.any_version_installed?
        tab = Tab.for_formula(f)
        resolved_spec = spec(nil) || tab.spec
        f.active_spec = resolved_spec if f.send(resolved_spec)
        f.build = tab
        if f.head? && tab.tabfile
          k = Keg.new(tab.tabfile.parent)
          f.version.update_commit(k.version.version.commit) if k.version.head?
        end
      end
    else
      rack = Formulary.to_rack(name)
      alias_path = Formulary.factory(name).alias_path
      f = Formulary.from_rack(rack, spec(nil), alias_path: alias_path)
    end

    # If this formula was installed with an alias that has since changed,
    # then it was specified explicitly in ARGV. (Using the alias would
    # instead have found the new formula.)
    #
    # Because of this, the user is referring to this specific formula,
    # not any formula targetted by the same alias, so in this context
    # the formula shouldn't be considered outdated if the alias used to
    # install it has changed.
    f.follow_installed_alias = false

    f
  end.uniq(&:name)
end

#sandbox?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'Library/Homebrew/extend/ARGV.rb', line 197

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

#switch?(char) ⇒ Boolean

eg. foo -ns -i --bar has three switches, n, s and i

Returns:

  • (Boolean)


271
272
273
274
# File 'Library/Homebrew/extend/ARGV.rb', line 271

def switch?(char)
  return false if char.length > 1
  options_only.any? { |arg| arg.scan("-").size == 1 && arg.include?(char) }
end

#value(name) ⇒ Object



144
145
146
147
148
# File 'Library/Homebrew/extend/ARGV.rb', line 144

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

#values(name) ⇒ Object

Returns an array of values that were given as a comma-seperated list.

See Also:



152
153
154
155
# File 'Library/Homebrew/extend/ARGV.rb', line 152

def values(name)
  return unless val = value(name)
  val.split(",")
end

#verbose?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'Library/Homebrew/extend/ARGV.rb', line 161

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