Merge pull request #5199 from GauthamGoli/desc-args
desc: Use CLI::Parser to parse args
This commit is contained in:
commit
f9bfa63167
@ -11,17 +11,42 @@
|
||||
require "descriptions"
|
||||
require "search"
|
||||
require "description_cache_store"
|
||||
require "cli_parser"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
extend Search
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
def desc
|
||||
desc_args.parse
|
||||
|
||||
search_type = []
|
||||
search_type << :either if ARGV.flag? "--search"
|
||||
search_type << :name if ARGV.flag? "--name"
|
||||
search_type << :desc if ARGV.flag? "--description"
|
||||
search_type << :either if args.search
|
||||
search_type << :name if args.name
|
||||
search_type << :desc if args.description
|
||||
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?
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user