Class: Homebrew::DevCmd::LivecheckCmd Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/livecheck.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::DevCmd::LivecheckCmd::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi', line 10

def args; end

#runvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Raises:



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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'dev-cmd/livecheck.rb', line 53

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

  eval_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(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 args.named.present?
      args.named.to_formulae_and_casks_with_taps
    elsif eval_all
      formulae = args.cask? ? [] : Formula.all(eval_all:)
      casks = args.formula? ? [] : Cask::Cask.all(eval_all:)
      formulae + casks
    elsif File.exist?(watchlist_path)
      begin
        # This removes blank lines, comment lines, and trailing comments
        names = Pathname.new(watchlist_path).read.lines
                        .filter_map do |line|
                          comment_index = line.index("#")
                          next if comment_index&.zero?

                          line = line[0...comment_index] if comment_index
                          line&.strip.presence
                        end

        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,
            "`brew livecheck` with no arguments needs a watchlist file to be present or `--eval-all` passed!"
    end
  end

  skipped_autobump = T.let(false, T::Boolean)
  if skip_autobump?
    autobump_lists = {}

    formulae_and_casks_to_check = formulae_and_casks_to_check.reject do |formula_or_cask|
      tap = formula_or_cask.tap
      next false if tap.nil?

      autobump_lists[tap] ||= tap.autobump

      name = formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
      next unless autobump_lists[tap].include?(name)

      odebug "Skipping #{name} as it is autobumped in #{tap}."
      skipped_autobump = true
      true
    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? && !skipped_autobump
  return 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