Class: Homebrew::Cmd::Desc

Inherits:
AbstractCommand show all
Defined in:
cmd/desc.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'cmd/desc.rb', line 40

def run
  search_type = if args.search?
    :either
  elsif args.name?
    :name
  elsif args.description?
    :desc
  end

  if search_type.present?
    if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
      raise UsageError, "`brew desc --search` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
    end

    query = args.named.join(" ")
    string_or_regex = Search.query_regexp(query)
    return Search.search_descriptions(string_or_regex, args, search_type:)
  end

  desc = {}
  args.named.to_formulae_and_casks.each do |formula_or_cask|
    case formula_or_cask
    when Formula
      desc[formula_or_cask.full_name] = formula_or_cask.desc
    when Cask::Cask
      description = formula_or_cask.desc.presence || Formatter.warning("[no 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
  Descriptions.new(desc).print
end