module Vint class Parser def initialize end protected def installed?(name) info = `brew info #{name}`.split(/\n/) if (info =~ /Error: /) || info.reverse[1] =~ /Not installed/ return false else return info[0].split(": ").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