Module: HomebrewArgvExtension

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

Instance Method Summary collapse

Instance Method Details

#bottle_archObject



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

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

#build_bottle?Boolean

Returns:

  • (Boolean)


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

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)


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

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)


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

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

#build_stable?Boolean

Returns:

  • (Boolean)


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

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

#build_universal?Boolean

Returns:

  • (Boolean)


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

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



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

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.



195
196
197
198
199
200
201
202
203
204
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 195

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)


108
109
110
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 108

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

#envObject



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

def env
  value "env"
end

#fetch_head?Boolean

Returns:

  • (Boolean)


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

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

#flag?(flag) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


100
101
102
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 100

def force?
  flag? "--force"
end

#force_bottle?Boolean

Returns:

  • (Boolean)


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

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)


124
125
126
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 124

def git?
  flag? "--git"
end

#homebrew_developer?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 128

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

#ignore_deps?Boolean

Returns:

  • (Boolean)


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

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

#interactive?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 116

def interactive?
  flag? "--interactive"
end

#keep_tmp?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 120

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
87
88
89
90
91
92
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 42

def kegs
  require "keg"
  require "formula"
  require "missing_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 : []

    if dirs.empty?
      if (reason = Homebrew::MissingFormula.suggest_command(name, "uninstall"))
        $stderr.puts reason
      end
      raise NoSuchKegError, rack.basename
    end

    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)


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

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)


112
113
114
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 112

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

#skip_or_later_bottles?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 132

def skip_or_later_bottles?
  homebrew_developer? && !ENV["HOMEBREW_SKIP_OR_LATER_BOTTLES"].nil?
end

#value(name) ⇒ Object



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

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)


104
105
106
# File 'brew/Library/Homebrew/extend/ARGV.rb', line 104

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