desc: better way to handle options
We allow to use options like --verbose and --debug for all commands. And we should support switch format options, e.g. `brew desc -vs foo`
This commit is contained in:
		
							parent
							
								
									12a4cf3808
								
							
						
					
					
						commit
						80514ee5d7
					
				@ -3,38 +3,24 @@ require "cmd/search"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
module Homebrew
 | 
					module Homebrew
 | 
				
			||||||
  def desc
 | 
					  def desc
 | 
				
			||||||
    if ARGV.options_only.empty?
 | 
					    search_type = []
 | 
				
			||||||
      if ARGV.named.empty?
 | 
					    search_type << :either if ARGV.flag? "--search"
 | 
				
			||||||
        raise FormulaUnspecifiedError
 | 
					    search_type << :name   if ARGV.flag? "--name"
 | 
				
			||||||
        exit
 | 
					    search_type << :desc   if ARGV.flag? "--description"
 | 
				
			||||||
      end
 | 
					
 | 
				
			||||||
      results = Descriptions.named(ARGV.formulae.map(&:full_name))
 | 
					    if search_type.empty?
 | 
				
			||||||
    else
 | 
					      raise FormulaUnspecifiedError if ARGV.named.empty?
 | 
				
			||||||
      if ARGV.options_only.count != 1
 | 
					      Descriptions.named(ARGV.formulae.map(&:full_name)).print
 | 
				
			||||||
 | 
					    elsif search_type.size > 1
 | 
				
			||||||
      odie "Pick one, and only one, of -s/--search, -n/--name, or -d/--description."
 | 
					      odie "Pick one, and only one, of -s/--search, -n/--name, or -d/--description."
 | 
				
			||||||
      end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      search_arg = ARGV.options_only.first
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      search_type = case search_arg
 | 
					 | 
				
			||||||
        when '-s', '--search'
 | 
					 | 
				
			||||||
          :either
 | 
					 | 
				
			||||||
        when '-n', '--name'
 | 
					 | 
				
			||||||
          :name
 | 
					 | 
				
			||||||
        when '-d', '--description'
 | 
					 | 
				
			||||||
          :desc
 | 
					 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
          odie "Unrecognized option '#{search_arg}'."
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if arg = ARGV.named.first
 | 
					      if arg = ARGV.named.first
 | 
				
			||||||
        regex = Homebrew::query_regexp(arg)
 | 
					        regex = Homebrew::query_regexp(arg)
 | 
				
			||||||
        results = Descriptions.search(regex, search_type)
 | 
					        results = Descriptions.search(regex, search_type.first)
 | 
				
			||||||
 | 
					        results.print
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
        odie "You must provide a search term."
 | 
					        odie "You must provide a search term."
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					 | 
				
			||||||
    results.print unless results.nil?
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@ require "blacklist"
 | 
				
			|||||||
require "utils"
 | 
					require "utils"
 | 
				
			||||||
require "thread"
 | 
					require "thread"
 | 
				
			||||||
require "official_taps"
 | 
					require "official_taps"
 | 
				
			||||||
require 'descriptions'
 | 
					require "descriptions"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module Homebrew
 | 
					module Homebrew
 | 
				
			||||||
  SEARCH_ERROR_QUEUE = Queue.new
 | 
					  SEARCH_ERROR_QUEUE = Queue.new
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user