diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb index 482f982ccb..2f64f5b393 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -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 diff --git a/Library/Homebrew/formula_support.rb b/Library/Homebrew/formula_support.rb index ec47639e38..b406f2321e 100644 --- a/Library/Homebrew/formula_support.rb +++ b/Library/Homebrew/formula_support.rb @@ -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 diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index 0d93c46ae5..32fb5d3657 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -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