Class: Homebrew::DevCmd::WhichUpdate Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/which-update.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/which_update.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::WhichUpdate::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/which_update.rbi', line 10

def args; end

#english_list(els, verb) ⇒ String

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.

Parameters:

Returns:



110
111
112
113
114
115
# File 'dev-cmd/which-update.rb', line 110

def english_list(els, verb)
  msg = +""
  msg << els.slice(0, 3)&.join(", ")
  msg << " and #{els.length - 3} more" if msg.length < 40 && els.length > 3
  "#{verb.capitalize} #{msg}"
end

#git_commit_message(changes) ⇒ String

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.

Parameters:

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'dev-cmd/which-update.rb', line 118

def git_commit_message(changes)
  msg = []
  ExecutablesDB::Changes::TYPES.each do |action|
    names = changes.send(action)
    next if names.empty?

    action = "bump version for" if action == :version_bump
    msg << english_list(names.to_a.sort, action.to_s)
    break
  end

  msg.join
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.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'dev-cmd/which-update.rb', line 40

def run
  if args.stats?
    stats source: args.named.fetch(0)
  else
    update_and_save! source:          args.named.fetch(0),
                     commit:          args.commit?,
                     update_existing: args.update_existing?,
                     install_missing: args.install_missing?,
                     max_downloads:   args.max_downloads&.to_i,
                     eval_all:        args.eval_all?,
                     summary_file:    args.summary_file
  end
end

#stats(source:) ⇒ void

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.

Parameters:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'dev-cmd/which-update.rb', line 55

def stats(source:)
  opoo "The DB file doesn't exist." unless File.exist? source
  db = ExecutablesDB.new source

  formulae = db.formula_names
  core = Formula.core_names

  cmds_count = db.exes.values.reduce(0) { |s, exs| s + exs.binaries.size }

  core_percentage = ((formulae & core).size * 1000 / core.size.to_f).round / 10.0

  missing = (core - formulae).reject { |f| Formula[f].disabled? }
  puts <<~EOS
    #{formulae.size} formulae
    #{cmds_count} commands
    #{core_percentage}%  (missing: #{missing * " "})
  EOS

  unknown = formulae - Formula.full_names
  puts "\nUnknown formulae: #{unknown * ", "}." if unknown.any?
  nil
end

#summary_file_message(changes) ⇒ String

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.

Parameters:

Returns:



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'dev-cmd/which-update.rb', line 133

def summary_file_message(changes)
  msg = []
  ExecutablesDB::Changes::TYPES.each do |action|
    names = changes.send(action)
    next if names.empty?

    action_heading = action.to_s.split("_").map(&:capitalize).join(" ")
    msg << "### #{action_heading}"
    msg << ""
    names.to_a.sort.each do |name|
      msg << "- [`#{name}`](https://formulae.brew.sh/formula/#{name})"
    end
  end

  msg << "No changes" if msg.empty?

  <<~MESSAGE
    ## Database Update Summary

    #{msg.join("\n")}
  MESSAGE
end

#update_and_save!(source:, commit: false, update_existing: false, install_missing: false, max_downloads: nil, eval_all: false, summary_file: nil) ⇒ void

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.

Parameters:

  • source (String)
  • commit (Boolean) (defaults to: false)
  • update_existing (Boolean) (defaults to: false)
  • install_missing (Boolean) (defaults to: false)
  • max_downloads (Integer, nil) (defaults to: nil)
  • eval_all (Boolean) (defaults to: false)
  • summary_file (String, nil) (defaults to: nil)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'dev-cmd/which-update.rb', line 89

def update_and_save!(source:, commit: false, update_existing: false, install_missing: false,
                     max_downloads: nil, eval_all: false, summary_file: nil)
  db = ExecutablesDB.new source
  db.update!(update_existing:, install_missing:,
             max_downloads:, eval_all:)
  db.save!

  if summary_file
    msg = summary_file_message(db.changes)
    File.open(summary_file, "a") do |file|
      file.puts(msg)
    end
  end

  return if !commit || !db.changed?

  msg = git_commit_message(db.changes)
  safe_system "git", "-C", db.root.to_s, "commit", "-m", msg, source
end