44 lines
1.4 KiB
Ruby
Raw Normal View History

2016-04-08 16:28:43 +02:00
#: * `desc` <formula>:
#: Display <formula>'s name and one-line description.
#:
#: * `desc` [`--search`|`--name`|`--description`] (<text>|`/`<text>`/`):
#: Search both name and description (`--search` or `-s`), just the names
#: (`--name` or `-n`), or just the descriptions (`--description` or `-d`) for
#: <text>. If <text> is flanked by slashes, it is interpreted as a regular
#: expression. Formula descriptions are cached; the cache is created on the
#: first search, making that search slower than subsequent ones.
2016-04-08 16:28:43 +02:00
require "descriptions"
2018-06-05 10:55:00 +02:00
require "search"
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
2018-06-05 10:55:00 +02:00
extend Search
def desc
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?
2018-09-17 02:45:00 +02:00
desc = {}
ARGV.formulae.each { |f| desc[f.full_name] = f.desc }
results = Descriptions.new(desc)
results.print
elsif search_type.size > 1
odie "Pick one, and only one, of -s/--search, -n/--name, or -d/--description."
2018-06-05 15:39:09 +02:00
elsif !ARGV.named.empty?
arg = ARGV.named.join(" ")
string_or_regex = query_regexp(arg)
results = Descriptions.search(string_or_regex, search_type.first)
2016-09-10 10:24:56 +01:00
results.print
else
2016-09-10 10:24:56 +01:00
odie "You must provide a search term."
end
end
end