Port Homebrew::Cmd::Desc
This commit is contained in:
parent
84222ec006
commit
1fc4a93ca1
@ -1,17 +1,15 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
require "descriptions"
|
require "descriptions"
|
||||||
require "search"
|
require "search"
|
||||||
require "description_cache_store"
|
require "description_cache_store"
|
||||||
require "cli/parser"
|
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module Cmd
|
||||||
|
class Desc < AbstractCommand
|
||||||
sig { returns(CLI::Parser) }
|
cmd_args do
|
||||||
def desc_args
|
|
||||||
Homebrew::CLI::Parser.new do
|
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Display <formula>'s name and one-line description.
|
Display <formula>'s name and one-line description.
|
||||||
The cache is created on the first search, making that search slower than subsequent ones.
|
The cache is created on the first search, making that search slower than subsequent ones.
|
||||||
@ -37,11 +35,9 @@ module Homebrew
|
|||||||
|
|
||||||
named_args [:formula, :cask, :text_or_regex], min: 1
|
named_args [:formula, :cask, :text_or_regex], min: 1
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def desc
|
|
||||||
args = desc_args.parse
|
|
||||||
|
|
||||||
|
sig { override.void }
|
||||||
|
def run
|
||||||
if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
|
if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
|
||||||
raise UsageError, "`brew desc` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
|
raise UsageError, "`brew desc` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
|
||||||
end
|
end
|
||||||
@ -57,11 +53,14 @@ module Homebrew
|
|||||||
if search_type.blank?
|
if search_type.blank?
|
||||||
desc = {}
|
desc = {}
|
||||||
args.named.to_formulae_and_casks.each do |formula_or_cask|
|
args.named.to_formulae_and_casks.each do |formula_or_cask|
|
||||||
if formula_or_cask.is_a? Formula
|
case formula_or_cask
|
||||||
|
when Formula
|
||||||
desc[formula_or_cask.full_name] = formula_or_cask.desc
|
desc[formula_or_cask.full_name] = formula_or_cask.desc
|
||||||
else
|
when Cask::Cask
|
||||||
description = formula_or_cask.desc.presence || Formatter.warning("[no description]")
|
description = formula_or_cask.desc.presence || Formatter.warning("[no description]")
|
||||||
desc[formula_or_cask.full_name] = "(#{formula_or_cask.name.join(", ")}) #{description}"
|
desc[formula_or_cask.full_name] = "(#{formula_or_cask.name.join(", ")}) #{description}"
|
||||||
|
else
|
||||||
|
raise TypeError, "Unsupported formula_or_cask type: #{formula_or_cask.class}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Descriptions.new(desc).print
|
Descriptions.new(desc).print
|
||||||
@ -71,4 +70,6 @@ module Homebrew
|
|||||||
Search.search_descriptions(string_or_regex, args, search_type:)
|
Search.search_descriptions(string_or_regex, args, search_type:)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cmd/desc"
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
|
||||||
RSpec.describe "brew desc" do
|
RSpec.describe Homebrew::Cmd::Desc do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
|
|
||||||
it "shows a given Formula's description", :integration_test do
|
it "shows a given Formula's description", :integration_test do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user