module Vintner class Parser def initialize end protected def installed?(name) installed = `brew list #{name} -v`.split(/\s/) if installed.size > 0 return installed.last end end def install(name, args={}) brewable = `brew info #{name}` if brewable =~ /^Error:/ puts "Error: No available formula for #{name}" exit 1 end if args[:url] system "brew install #{args[:url]} >& /dev/null" else system "brew install #{name} >& /dev/null" end end def brew(formula, args={}) installed_version = installed?(formula) puts "#{installed_version ? "Using" : "Installing"} #{formula} #{installed_version ? "(#{installed_version})" : "..."}" install(formula, args) unless installed_version end public def parse(brewfile) begin eval(File.open(brewfile).read) puts "All of formula in Brewfile is installed!" rescue => e puts e exit 1 end end end end