From c1220975b91d7627ce8b868e2ee36bcabe908fc2 Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Tue, 28 Aug 2012 10:59:46 -0700 Subject: [PATCH] Refactor brew list --- Library/Homebrew/cmd/list.rb | 45 +++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 54292f513b..602396e4a7 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -1,31 +1,44 @@ module Homebrew extend self def list - # Cellar doesn't until the first formula is installed. + + # Use of exec means we don't explicitly exit + list_unbrewed if ARGV.flag? '--unbrewed' + + # Unbrewed uses the PREFIX, which will exist + # Things below use the CELLAR, which doesn't until the first formula is installed. return unless HOMEBREW_CELLAR.exist? - if ARGV.flag? '--unbrewed' - dirs = HOMEBREW_PREFIX.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s } - dirs -= %w[Library Cellar .git] - cd HOMEBREW_PREFIX - exec 'find', *dirs + %w[-type f ( ! -iname .ds_store ! -iname brew ! -iname brew-man.1 ! -iname brew.1 )] - elsif ARGV.flag? '--versions' - if ARGV.named.empty? - HOMEBREW_CELLAR.children.select{ |pn| pn.directory? } - else - ARGV.named.map{ |n| HOMEBREW_CELLAR+n }.select{ |pn| pn.exist? } - end.each do |d| - versions = d.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s } - puts "#{d.basename} #{versions*' '}" - end + if ARGV.flag? '--versions' + list_versions elsif ARGV.named.empty? ENV['CLICOLOR'] = nil - exec 'ls', *ARGV.options_only << HOMEBREW_CELLAR if HOMEBREW_CELLAR.exist? + exec 'ls', *ARGV.options_only << HOMEBREW_CELLAR elsif ARGV.verbose? or not $stdout.tty? exec "find", *ARGV.kegs + %w[-not -type d -print] else ARGV.kegs.each{ |keg| PrettyListing.new keg } end end + +private + + def list_unbrewed + dirs = HOMEBREW_PREFIX.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s } + dirs -= %w[Library Cellar .git] + cd HOMEBREW_PREFIX + exec 'find', *dirs + %w[-type f ( ! -iname .ds_store ! -iname brew ! -iname brew-man.1 ! -iname brew.1 )] + end + + def list_versions + if ARGV.named.empty? + HOMEBREW_CELLAR.children.select{ |pn| pn.directory? } + else + ARGV.named.map{ |n| HOMEBREW_CELLAR+n }.select{ |pn| pn.exist? } + end.each do |d| + versions = d.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s } + puts "#{d.basename} #{versions*' '}" + end + end end class PrettyListing