brew-bundle: cleanup path handling.

This commit is contained in:
Mike McQuaid 2013-11-17 09:41:41 +00:00
parent de12583bb8
commit c3b32c0189

View File

@ -4,28 +4,31 @@
# #
# Looks for a Brewfile and runs each line as a brew command. # Looks for a Brewfile and runs each line as a brew command.
# #
# brew bundle # Looks for "./brewfile" # brew bundle # Looks for "./Brewfile"
# brew bundle path/to/dir # Looks for "./path/to/dir/brewfile" # brew bundle path/to/dir # Looks for "./path/to/dir/Brewfile"
# brew bundle path/to/file # Looks for "./path/to/file" # brew bundle path/to/file # Looks for "./path/to/file"
# #
# For example, given a Brewfile with the following contents: # For example, given a Brewfile with the following contents:
#
# tap foo/bar # tap foo/bar
# install spark # install spark
# #
# Running `brew bundle` will run the commands `brew tap foo/bar` # Running `brew bundle` will run the commands `brew tap foo/bar`
# and `brew install spark`. # and `brew install spark`.
if ARGV.empty? then path = 'Brewfile'
path = 'brewfile' error = ' in current directory'
else
path = ARGV[0] if ARGV.first
if File.directory? path then if File.directory? ARGV.first
path = path + '/brewfile' path = "#{ARGV.first}/#{path}"
end error = " in '#{ARGV.first}'"
else
path = ARGV.first
error = " at '#{ARGV.first}'"
end
end end
raise "No such Brewfile: #{path}" unless File.exist? path raise "Cannot find Brewfile#{error}" unless File.exist? path
File.readlines(path).each do |line| File.readlines(path).each do |line|
command = line.chomp command = line.chomp