From 80514ee5d7f981c820d453baa70a189ad693280d Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Wed, 9 Sep 2015 13:00:43 +0800 Subject: 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` --- Library/Homebrew/cmd/desc.rb | 38 ++++++++++++-------------------------- Library/Homebrew/cmd/search.rb | 2 +- 2 files changed, 13 insertions(+), 27 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cmd/desc.rb b/Library/Homebrew/cmd/desc.rb index 77078e8f5..dab18fc91 100644 --- a/Library/Homebrew/cmd/desc.rb +++ b/Library/Homebrew/cmd/desc.rb @@ -3,38 +3,24 @@ require "cmd/search" module Homebrew def desc - if ARGV.options_only.empty? - if ARGV.named.empty? - raise FormulaUnspecifiedError - exit - end - results = Descriptions.named(ARGV.formulae.map(&:full_name)) - else - if ARGV.options_only.count != 1 - 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 - odie "Unrecognized option '#{search_arg}'." - end + search_type = [] + search_type << :either if ARGV.flag? "--search" + search_type << :name if ARGV.flag? "--name" + search_type << :desc if ARGV.flag? "--description" + if search_type.empty? + raise FormulaUnspecifiedError if ARGV.named.empty? + 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." + else if arg = ARGV.named.first regex = Homebrew::query_regexp(arg) - results = Descriptions.search(regex, search_type) + results = Descriptions.search(regex, search_type.first) + results.print else odie "You must provide a search term." end end - - results.print unless results.nil? end end diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 9e5f28815..393e90fda 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -3,7 +3,7 @@ require "blacklist" require "utils" require "thread" require "official_taps" -require 'descriptions' +require "descriptions" module Homebrew SEARCH_ERROR_QUEUE = Queue.new -- cgit v1.2.3