Support multiple formulae for certain commands
This commit is contained in:
		
							parent
							
								
									96ddd7ee05
								
							
						
					
					
						commit
						3eeda7fc29
					
				
							
								
								
									
										56
									
								
								bin/brew
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								bin/brew
									
									
									
									
									
								
							@ -34,9 +34,8 @@ def prune
 | 
				
			|||||||
  return n
 | 
					  return n
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def shift_formulae
 | 
					def formulize name
 | 
				
			||||||
  name=Pathname.new ARGV.shift
 | 
					  name=Pathname.new name
 | 
				
			||||||
 | 
					 | 
				
			||||||
  return name if name.directory? and name.parent.realpath == $cellar
 | 
					  return name if name.directory? and name.parent.realpath == $cellar
 | 
				
			||||||
  return File.basename(name, '.rb') if name.file? and name.extname == '.rb' and name.parent.realpath == $formula
 | 
					  return File.basename(name, '.rb') if name.file? and name.extname == '.rb' and name.parent.realpath == $formula
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -49,6 +48,15 @@ def shift_formulae
 | 
				
			|||||||
  raise "No formula or keg for #{name} found"
 | 
					  raise "No formula or keg for #{name} found"
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def shift_formulae_from_ARGV
 | 
				
			||||||
 | 
					  fae=Array.new
 | 
				
			||||||
 | 
					  while name=ARGV[0]
 | 
				
			||||||
 | 
					    fae<<formulize(ARGV.shift).to_s unless name[0] == '-'
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  raise "You must specify a formula" if fae.empty?
 | 
				
			||||||
 | 
					  return fae
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def __class name
 | 
					def __class name
 | 
				
			||||||
  #remove invalid characters and camelcase
 | 
					  #remove invalid characters and camelcase
 | 
				
			||||||
  name.capitalize.gsub(/[-_\s]([a-zA-Z0-9])/) { $1.upcase }
 | 
					  name.capitalize.gsub(/[-_\s]([a-zA-Z0-9])/) { $1.upcase }
 | 
				
			||||||
@ -167,11 +175,9 @@ end
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
######################################################################### impl
 | 
					######################################################################### impl
 | 
				
			||||||
begin
 | 
					begin
 | 
				
			||||||
  #TODO proper options parsing so --options can go first if necessary
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  case ARGV.shift
 | 
					  case ARGV.shift
 | 
				
			||||||
    when 'abv'
 | 
					    when 'abv'
 | 
				
			||||||
      `find #{$cellar} -type f | wc -l`.strip+' files, '+`du -hd0 #{$cellar} | cut -d"\t" -f1`.strip
 | 
					      puts `find #{$cellar} -type f | wc -l`.strip+' files, '+`du -hd0 #{$cellar} | cut -d"\t" -f1`.strip
 | 
				
			||||||
    when 'prune'
 | 
					    when 'prune'
 | 
				
			||||||
      puts "Pruned #{prune} files"
 | 
					      puts "Pruned #{prune} files"
 | 
				
			||||||
    when '--prefix'
 | 
					    when '--prefix'
 | 
				
			||||||
@ -187,27 +193,31 @@ begin
 | 
				
			|||||||
    when '-v', '--version'
 | 
					    when '-v', '--version'
 | 
				
			||||||
      puts HOMEBREW_VERSION
 | 
					      puts HOMEBREW_VERSION
 | 
				
			||||||
    when 'list'
 | 
					    when 'list'
 | 
				
			||||||
      puts `find #{$cellar+shift_formulae}`
 | 
					      fae=shift_formulae_from_ARGV.collect {|name| ($cellar+name).to_s}
 | 
				
			||||||
 | 
					      puts `find #{fae.join' '}`
 | 
				
			||||||
    when 'install'
 | 
					    when 'install'
 | 
				
			||||||
      name=shift_formulae
 | 
					      shift_formulae_from_ARGV.each do |name|
 | 
				
			||||||
      beginning = Time.now
 | 
					        beginning = Time.now
 | 
				
			||||||
      o=__obj(name)
 | 
					        o=__obj(name)
 | 
				
			||||||
      raise "#{o.prefix} already exists!" if o.prefix.exist?
 | 
					        raise "#{o.prefix} already exists!" if o.prefix.exist?
 | 
				
			||||||
      o.prefix.mkpath
 | 
					        o.prefix.mkpath
 | 
				
			||||||
      o.brew { o.install }
 | 
					        o.brew { o.install }
 | 
				
			||||||
      ohai 'Finishing up'
 | 
					        ohai 'Finishing up'
 | 
				
			||||||
      o.clean
 | 
					        o.clean
 | 
				
			||||||
      ln name
 | 
					        ln name
 | 
				
			||||||
      puts "#{o.prefix}: "+`find #{o.prefix} -type f | wc -l`.strip+
 | 
					        puts "#{o.prefix}: "+`find #{o.prefix} -type f | wc -l`.strip+
 | 
				
			||||||
                           ' files, '+
 | 
					                             ' files, '+
 | 
				
			||||||
                           `du -hd0 #{o.prefix} | cut -d"\t" -f1`.strip+
 | 
					                             `du -hd0 #{o.prefix} | cut -d"\t" -f1`.strip+
 | 
				
			||||||
                           ", built in #{Time.now - beginning} seconds"
 | 
					                             ", built in #{Time.now - beginning} seconds"
 | 
				
			||||||
 | 
					     end
 | 
				
			||||||
    when 'ln'
 | 
					    when 'ln'
 | 
				
			||||||
      puts "Created #{ln shift_formulae} links"
 | 
					      n=0
 | 
				
			||||||
 | 
					      shift_formulae_from_ARGV.each {|name| n+=ln name}
 | 
				
			||||||
 | 
					      puts "Created #{n} links"
 | 
				
			||||||
    when 'rm'
 | 
					    when 'rm'
 | 
				
			||||||
      rm shift_formulae
 | 
					      shift_formulae_from_ARGV.each {|name| rm name}
 | 
				
			||||||
    when 'info'
 | 
					    when 'info'
 | 
				
			||||||
      o=__obj shift_formulae
 | 
					      o=__obj shift_formulae_from_ARGV[0]
 | 
				
			||||||
      puts "#{o.name} #{o.version}"
 | 
					      puts "#{o.name} #{o.version}"
 | 
				
			||||||
      puts o.homepage
 | 
					      puts o.homepage
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user