Simplify build options API
Simplify access to the different forms of a formula's build options by making options into real objects rather than strings, and expose both the 'name' and 'flag' form.
This commit is contained in:
parent
9b1bb58214
commit
3f9e88ae69
@ -21,7 +21,7 @@ module Homebrew extend self
|
||||
ff.each do |f|
|
||||
next if f.build.empty?
|
||||
if ARGV.include? '--compact'
|
||||
puts f.build.collect {|k,v| "--"+k} * " "
|
||||
puts f.build.as_flags * " "
|
||||
else
|
||||
puts f.name if ff.length > 1
|
||||
dump_options_for_formula f
|
||||
@ -31,9 +31,9 @@ module Homebrew extend self
|
||||
end
|
||||
|
||||
def dump_options_for_formula f
|
||||
f.build.each do |k,v|
|
||||
puts "--"+k
|
||||
puts "\t"+v
|
||||
f.build.each do |opt|
|
||||
puts opt.flag
|
||||
puts "\t"+opt.description
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -162,6 +162,26 @@ class KegOnlyReason
|
||||
end
|
||||
|
||||
|
||||
# Represents a build-time option for a formula
|
||||
class Option
|
||||
attr_reader :name, :description, :flag
|
||||
|
||||
def initialize name, description=nil
|
||||
@name = name.to_s
|
||||
@description = description.to_s
|
||||
@flag = '--'+name.to_s
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
@name == other.name
|
||||
end
|
||||
|
||||
def hash
|
||||
@name.hash
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# This class holds the build-time options defined for a Formula,
|
||||
# and provides named access to those options during install.
|
||||
class BuildOptions
|
||||
@ -187,19 +207,23 @@ class BuildOptions
|
||||
end
|
||||
end
|
||||
|
||||
@options << [name, description]
|
||||
@options << Option.new(name, description)
|
||||
end
|
||||
|
||||
def has_option? name
|
||||
@options.any? { |opt, _| opt == name }
|
||||
any? { |opt| opt.name == name }
|
||||
end
|
||||
|
||||
def empty?
|
||||
@options.empty?
|
||||
end
|
||||
|
||||
def each
|
||||
@options.each { |opt, desc| yield opt, desc }
|
||||
def each(&blk)
|
||||
@options.each(&blk)
|
||||
end
|
||||
|
||||
def as_flags
|
||||
map { |opt| opt.flag }
|
||||
end
|
||||
|
||||
def include? name
|
||||
|
@ -13,7 +13,7 @@ class Tab < OpenStruct
|
||||
arg_options = args.options_only
|
||||
# Pick off the option flags from the formula's `options` array by
|
||||
# discarding the descriptions.
|
||||
formula_options = f.build.map { |opt, _| "--#{opt}" }
|
||||
formula_options = f.build.as_flags
|
||||
|
||||
Tab.new :used_options => formula_options & arg_options,
|
||||
:unused_options => formula_options - arg_options,
|
||||
@ -67,7 +67,7 @@ class Tab < OpenStruct
|
||||
|
||||
def self.dummy_tab f
|
||||
Tab.new :used_options => [],
|
||||
:unused_options => f.build.map { |opt, _| "--#{opt}" },
|
||||
:unused_options => f.build.as_flags,
|
||||
:built_bottle => false,
|
||||
:tapped_from => ""
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user