2015-05-05 15:29:01 -07:00
|
|
|
require "descriptions"
|
2018-06-05 10:55:00 +02:00
|
|
|
require "search"
|
2018-10-13 08:22:51 -07:00
|
|
|
require "description_cache_store"
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2015-05-05 15:29:01 -07:00
|
|
|
|
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2018-06-05 10:55:00 +02:00
|
|
|
extend Search
|
|
|
|
|
2018-10-25 12:27:12 +05:30
|
|
|
def desc_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
|
|
|
`desc` [<options>] (<text>|`/`<text>`/`|<formula>)
|
|
|
|
|
|
|
|
Display <formula>'s name and one-line description.
|
|
|
|
Formula descriptions are cached; the cache is created on the
|
|
|
|
first search, making that search slower than subsequent ones.
|
|
|
|
EOS
|
|
|
|
flag "-s", "--search=",
|
|
|
|
description: "Search both name and description for provided <text>. If <text> is flanked by "\
|
|
|
|
"slashes, it is interpreted as a regular expression."
|
|
|
|
flag "-n", "--name=",
|
|
|
|
description: "Search just the names for provided <text>. If <text> is flanked by slashes, it is "\
|
|
|
|
"interpreted as a regular expression."
|
|
|
|
flag "-d", "--description=",
|
|
|
|
description: "Search just the descriptions for provided <text>. If <text> is flanked by slashes, "\
|
|
|
|
"it is interpreted as a regular expression."
|
|
|
|
switch :verbose
|
2019-01-29 19:39:41 +00:00
|
|
|
conflicts "--search=", "--name=", "--description="
|
2018-10-25 12:27:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-05 15:29:01 -07:00
|
|
|
def desc
|
2018-10-25 12:27:12 +05:30
|
|
|
desc_args.parse
|
|
|
|
|
2015-09-09 13:00:43 +08:00
|
|
|
search_type = []
|
2018-10-25 12:27:12 +05:30
|
|
|
search_type << :either if args.search
|
|
|
|
search_type << :name if args.name
|
|
|
|
search_type << :desc if args.description
|
2018-10-13 08:22:51 -07:00
|
|
|
if search_type.size > 1
|
|
|
|
odie "Pick one, and only one, of -s/--search, -n/--name, or -d/--description."
|
|
|
|
elsif search_type.present? && ARGV.named.empty?
|
|
|
|
odie "You must provide a search term."
|
|
|
|
end
|
2015-05-05 15:29:01 -07:00
|
|
|
|
2018-10-13 08:22:51 -07:00
|
|
|
results = if search_type.empty?
|
2015-09-09 13:00:43 +08:00
|
|
|
raise FormulaUnspecifiedError if ARGV.named.empty?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2015-09-09 15:21:18 +08:00
|
|
|
desc = {}
|
|
|
|
ARGV.formulae.each { |f| desc[f.full_name] = f.desc }
|
2018-10-13 08:22:51 -07:00
|
|
|
Descriptions.new(desc)
|
|
|
|
else
|
2018-06-05 15:39:09 +02:00
|
|
|
arg = ARGV.named.join(" ")
|
|
|
|
string_or_regex = query_regexp(arg)
|
2018-10-13 08:22:51 -07:00
|
|
|
CacheStoreDatabase.use(:descriptions) do |db|
|
|
|
|
cache_store = DescriptionCacheStore.new(db)
|
|
|
|
Descriptions.search(string_or_regex, search_type.first, cache_store)
|
|
|
|
end
|
2015-05-05 15:29:01 -07:00
|
|
|
end
|
2018-10-13 08:22:51 -07:00
|
|
|
|
|
|
|
results.print
|
2015-05-05 15:29:01 -07:00
|
|
|
end
|
|
|
|
end
|