Class: Homebrew::DevCmd::LivecheckCmd

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/livecheck.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.

Raises:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'dev-cmd/livecheck.rb', line 51

def run
  Homebrew.install_bundler_gems!(groups: ["livecheck"])

  all = args.eval_all?

  if args.debug? && args.verbose?
    puts args
    puts Homebrew::EnvConfig.livecheck_watchlist if Homebrew::EnvConfig.livecheck_watchlist.present?
  end

  formulae_and_casks_to_check = Homebrew.with_no_api_env do
    if args.tap
      tap = Tap.fetch(T.must(args.tap))
      formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) }
      casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }
      formulae + casks
    elsif args.installed?
      formulae = args.cask? ? [] : Formula.installed
      casks = args.formula? ? [] : Cask::Caskroom.casks
      formulae + casks
    elsif all
      formulae = args.cask? ? [] : Formula.all(eval_all: args.eval_all?)
      casks = args.formula? ? [] : Cask::Cask.all(eval_all: args.eval_all?)
      formulae + casks
    elsif args.named.present?
      if args.formula?
        args.named.to_formulae
      elsif args.cask?
        args.named.to_casks
      else
        args.named.to_formulae_and_casks
      end
    elsif File.exist?(watchlist_path)
      begin
        names = Pathname.new(watchlist_path).read.lines
                        .reject { |line| line.start_with?("#") || line.blank? }
                        .map(&:strip)

        named_args = CLI::NamedArgs.new(*names, parent: args)
        named_args.to_formulae_and_casks(ignore_unavailable: true)
      rescue Errno::ENOENT => e
        onoe e
      end
    else
      raise UsageError, "A watchlist file is required when no arguments are given."
    end
  end

  formulae_and_casks_to_check = formulae_and_casks_to_check.sort_by do |formula_or_cask|
    formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
  end

  raise UsageError, "No formulae or casks to check." if formulae_and_casks_to_check.blank?

  options = {
    json:                 args.json?,
    full_name:            args.full_name?,
    handle_name_conflict: !args.formula? && !args.cask?,
    check_resources:      args.resources?,
    newer_only:           args.newer_only?,
    extract_plist:        args.extract_plist?,
    quiet:                args.quiet?,
    debug:                args.debug?,
    verbose:              args.verbose?,
  }.compact

  Livecheck.run_checks(formulae_and_casks_to_check, **options)
end