diff options
| author | Xu Cheng | 2015-09-09 13:00:43 +0800 |
|---|---|---|
| committer | Xu Cheng | 2015-09-10 13:37:57 +0800 |
| commit | 80514ee5d7f981c820d453baa70a189ad693280d (patch) | |
| tree | f21f18643a9976970bea313c107f50017db47653 | |
| parent | 12a4cf380814305c6972274dbee823414d5d200d (diff) | |
| download | brew-80514ee5d7f981c820d453baa70a189ad693280d.tar.bz2 | |
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`
| -rw-r--r-- | Library/Homebrew/cmd/desc.rb | 38 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/search.rb | 2 |
2 files changed, 13 insertions, 27 deletions
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 |
