Merge pull request #910 from MikeMcQuaid/cmd-rubocop
Fix Library/Homebrew/cmd RuboCop warnings
This commit is contained in:
commit
ea0405c8dd
@ -41,22 +41,20 @@ module Homebrew
|
||||
end
|
||||
|
||||
def external_commands
|
||||
paths.reduce([]) do |cmds, path|
|
||||
paths.each_with_object([]) do |path, cmds|
|
||||
Dir["#{path}/brew-*"].each do |file|
|
||||
next unless File.executable?(file)
|
||||
cmd = File.basename(file, ".rb")[5..-1]
|
||||
cmds << cmd unless cmd.include?(".")
|
||||
end
|
||||
cmds
|
||||
end.sort
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_internal_commands(directory)
|
||||
directory.children.reduce([]) do |cmds, f|
|
||||
directory.children.each_with_object([]) do |f, cmds|
|
||||
cmds << f.basename.to_s.sub(/\.(?:rb|sh)$/, "") if f.file?
|
||||
cmds
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -26,14 +26,12 @@ module Homebrew
|
||||
results.print
|
||||
elsif search_type.size > 1
|
||||
odie "Pick one, and only one, of -s/--search, -n/--name, or -d/--description."
|
||||
elsif arg = ARGV.named.first
|
||||
regex = Homebrew.query_regexp(arg)
|
||||
results = Descriptions.search(regex, search_type.first)
|
||||
results.print
|
||||
else
|
||||
if arg = ARGV.named.first
|
||||
regex = Homebrew::query_regexp(arg)
|
||||
results = Descriptions.search(regex, search_type.first)
|
||||
results.print
|
||||
else
|
||||
odie "You must provide a search term."
|
||||
end
|
||||
odie "You must provide a search term."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -40,20 +40,19 @@ module Homebrew
|
||||
end
|
||||
|
||||
out = checks.send(method)
|
||||
unless out.nil? || out.empty?
|
||||
if first_warning
|
||||
$stderr.puts <<-EOS.undent
|
||||
next if out.nil? || out.empty?
|
||||
if first_warning
|
||||
$stderr.puts <<-EOS.undent
|
||||
#{Tty.white}Please note that these warnings are just used to help the Homebrew maintainers
|
||||
with debugging if you file an issue. If everything you use Homebrew for is
|
||||
working fine: please don't worry and just ignore them. Thanks!#{Tty.reset}
|
||||
EOS
|
||||
end
|
||||
|
||||
$stderr.puts
|
||||
opoo out
|
||||
Homebrew.failed = true
|
||||
first_warning = false
|
||||
EOS
|
||||
end
|
||||
|
||||
$stderr.puts
|
||||
opoo out
|
||||
Homebrew.failed = true
|
||||
first_warning = false
|
||||
end
|
||||
|
||||
puts "Your system is ready to brew." unless Homebrew.failed?
|
||||
|
||||
@ -56,11 +56,10 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
unless fetched_bottle
|
||||
fetch_formula(f)
|
||||
f.resources.each { |r| fetch_resource(r) }
|
||||
f.patchlist.each { |p| fetch_patch(p) if p.external? }
|
||||
end
|
||||
next if fetched_bottle
|
||||
fetch_formula(f)
|
||||
f.resources.each { |r| fetch_resource(r) }
|
||||
f.patchlist.each { |p| fetch_patch(p) if p.external? }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
HOMEBREW_HELP = <<-EOS
|
||||
HOMEBREW_HELP = <<-EOS.freeze
|
||||
Example usage:
|
||||
brew search [TEXT|/REGEX/]
|
||||
brew (info|home|options) [FORMULA...]
|
||||
@ -78,11 +78,11 @@ module Homebrew
|
||||
HOMEBREW_HELP
|
||||
else
|
||||
help_lines.map do |line|
|
||||
line.slice(2..-1).
|
||||
sub(/^ \* /, "#{Tty.highlight}brew#{Tty.reset} ").
|
||||
gsub(/`(.*?)`/, "#{Tty.highlight}\\1#{Tty.reset}").
|
||||
gsub(/<(.*?)>/, "#{Tty.em}\\1#{Tty.reset}").
|
||||
gsub("@hide_from_man_page", "")
|
||||
line.slice(2..-1)
|
||||
.sub(/^ \* /, "#{Tty.highlight}brew#{Tty.reset} ")
|
||||
.gsub(/`(.*?)`/, "#{Tty.highlight}\\1#{Tty.reset}")
|
||||
.gsub(/<(.*?)>/, "#{Tty.em}\\1#{Tty.reset}")
|
||||
.gsub("@hide_from_man_page", "")
|
||||
end.join.strip
|
||||
end
|
||||
end
|
||||
|
||||
@ -45,7 +45,7 @@ module Homebrew
|
||||
end
|
||||
else
|
||||
ARGV.named.each_with_index do |f, i|
|
||||
puts unless i == 0
|
||||
puts unless i.zero?
|
||||
begin
|
||||
if f.include?("/") || File.exist?(f)
|
||||
info_formula Formulary.factory(f)
|
||||
|
||||
@ -71,13 +71,16 @@ module Homebrew
|
||||
raise "Specify `--HEAD` in uppercase to build from trunk."
|
||||
end
|
||||
|
||||
ARGV.named.each do |name|
|
||||
if !File.exist?(name) &&
|
||||
(name =~ HOMEBREW_TAP_FORMULA_REGEX || name =~ HOMEBREW_CASK_TAP_FORMULA_REGEX)
|
||||
unless ARGV.force?
|
||||
ARGV.named.each do |name|
|
||||
next if File.exist?(name)
|
||||
if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_FORMULA_REGEX
|
||||
next
|
||||
end
|
||||
tap = Tap.fetch($1, $2)
|
||||
tap.install unless tap.installed?
|
||||
end
|
||||
end unless ARGV.force?
|
||||
end
|
||||
|
||||
begin
|
||||
formulae = []
|
||||
|
||||
@ -29,7 +29,7 @@ module Homebrew
|
||||
# Unbrewed uses the PREFIX, which will exist
|
||||
# Things below use the CELLAR, which doesn't until the first formula is installed.
|
||||
unless HOMEBREW_CELLAR.exist?
|
||||
raise NoSuchKegError.new(ARGV.named.first) unless ARGV.named.empty?
|
||||
raise NoSuchKegError, ARGV.named.first unless ARGV.named.empty?
|
||||
return
|
||||
end
|
||||
|
||||
@ -60,7 +60,7 @@ module Homebrew
|
||||
|
||||
private
|
||||
|
||||
UNBREWED_EXCLUDE_FILES = %w[.DS_Store]
|
||||
UNBREWED_EXCLUDE_FILES = %w[.DS_Store].freeze
|
||||
UNBREWED_EXCLUDE_PATHS = %w[
|
||||
.github/*
|
||||
bin/brew
|
||||
@ -80,7 +80,7 @@ module Homebrew
|
||||
share/man/man1/brew.1
|
||||
share/man/whatis
|
||||
share/zsh/site-functions/_brew
|
||||
]
|
||||
].freeze
|
||||
|
||||
def list_unbrewed
|
||||
dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s }
|
||||
@ -117,7 +117,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
pinned_versions.each do |d, version|
|
||||
puts "#{d.basename}".concat(ARGV.include?("--versions") ? " #{version}" : "")
|
||||
puts d.basename.to_s.concat(ARGV.include?("--versions") ? " #{version}" : "")
|
||||
end
|
||||
else # --versions without --pinned
|
||||
names.each do |d|
|
||||
|
||||
@ -18,7 +18,7 @@ module Homebrew
|
||||
|
||||
private
|
||||
|
||||
def git_log(path=nil)
|
||||
def git_log(path = nil)
|
||||
if File.exist? "#{`git rev-parse --show-toplevel`.chomp}/.git/shallow"
|
||||
opoo <<-EOS.undent
|
||||
The git repository is a shallow clone therefore the filtering may be incorrect.
|
||||
|
||||
@ -18,7 +18,7 @@ module Homebrew
|
||||
|
||||
Diagnostic.missing_deps(ff) do |name, missing|
|
||||
print "#{name}: " if ff.size > 1
|
||||
puts "#{missing * " "}"
|
||||
puts (missing * " ").to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -47,14 +47,16 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
if ObserverPathnameExtension.total.zero?
|
||||
puts "Nothing pruned" if ARGV.verbose?
|
||||
else
|
||||
n, d = ObserverPathnameExtension.counts
|
||||
print "Pruned #{n} symbolic links "
|
||||
print "and #{d} directories " if d > 0
|
||||
puts "from #{HOMEBREW_PREFIX}"
|
||||
end unless ARGV.dry_run?
|
||||
unless ARGV.dry_run?
|
||||
if ObserverPathnameExtension.total.zero?
|
||||
puts "Nothing pruned" if ARGV.verbose?
|
||||
else
|
||||
n, d = ObserverPathnameExtension.counts
|
||||
print "Pruned #{n} symbolic links "
|
||||
print "and #{d} directories " if d > 0
|
||||
puts "from #{HOMEBREW_PREFIX}"
|
||||
end
|
||||
end
|
||||
|
||||
unlinkapps_prune(:dry_run => ARGV.dry_run?, :quiet => true)
|
||||
end
|
||||
|
||||
@ -71,7 +71,7 @@ module Homebrew
|
||||
puts
|
||||
end
|
||||
puts msg
|
||||
elsif count == 0
|
||||
elsif count.zero?
|
||||
puts "No formula found for #{query.inspect}."
|
||||
begin
|
||||
GitHub.print_pull_requests_matching(query)
|
||||
@ -100,7 +100,7 @@ module Homebrew
|
||||
|
||||
SEARCHABLE_TAPS = OFFICIAL_TAPS.map { |tap| ["Homebrew", tap] } + [
|
||||
%w[Caskroom cask],
|
||||
%w[Caskroom versions]
|
||||
%w[Caskroom versions],
|
||||
]
|
||||
|
||||
def query_regexp(query)
|
||||
@ -151,7 +151,7 @@ module Homebrew
|
||||
names = remote_tap_formulae["#{user}/#{repo}"]
|
||||
user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization
|
||||
names.select { |name| rx === name }.map { |name| "#{user}/#{repo}/#{name}" }
|
||||
rescue GitHub::HTTPNotFoundError => e
|
||||
rescue GitHub::HTTPNotFoundError
|
||||
opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
|
||||
[]
|
||||
rescue GitHub::Error => e
|
||||
|
||||
@ -59,7 +59,7 @@ module Homebrew
|
||||
puts info
|
||||
else
|
||||
taps.each_with_index do |tap, i|
|
||||
puts unless i == 0
|
||||
puts unless i.zero?
|
||||
info = "#{tap}: "
|
||||
if tap.installed?
|
||||
info += tap.pinned? ? "pinned" : "unpinned"
|
||||
@ -70,7 +70,7 @@ module Homebrew
|
||||
if (command_count = tap.command_files.size) > 0
|
||||
info += ", #{command_count} command#{plural(command_count)}"
|
||||
end
|
||||
info += ", no formulae/commands" if formula_count + command_count == 0
|
||||
info += ", no formulae/commands" if (formula_count + command_count).zero?
|
||||
info += "\n#{tap.path} (#{tap.path.abv})"
|
||||
info += "\nFrom: #{tap.remote.nil? ? "N/A" : tap.remote}"
|
||||
else
|
||||
|
||||
@ -60,6 +60,8 @@ module Homebrew
|
||||
end
|
||||
|
||||
def rm_pin(rack)
|
||||
Formulary.from_rack(rack).unpin rescue nil
|
||||
Formulary.from_rack(rack).unpin
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -65,7 +65,7 @@ module Homebrew
|
||||
|
||||
def unlinkapps_unlink?(target_app, opts = {})
|
||||
# Skip non-symlinks and symlinks that don't point into the Homebrew prefix.
|
||||
app = "#{target_app.readlink}" if target_app.symlink?
|
||||
app = target_app.readlink.to_s if target_app.symlink?
|
||||
return false unless app && app.start_with?(*UNLINKAPPS_PREFIXES)
|
||||
|
||||
if opts.fetch(:prune, false)
|
||||
|
||||
@ -43,13 +43,12 @@ module Homebrew
|
||||
end
|
||||
ENV["VERBOSE"] = nil
|
||||
|
||||
if ARGV.git?
|
||||
ohai "Setting up git repository"
|
||||
cd stage_dir
|
||||
system "git", "init", "-q"
|
||||
system "git", "add", "-A"
|
||||
system "git", "commit", "-q", "-m", "brew-unpack"
|
||||
end
|
||||
next unless ARGV.git?
|
||||
ohai "Setting up git repository"
|
||||
cd stage_dir
|
||||
system "git", "init", "-q"
|
||||
system "git", "add", "-A"
|
||||
system "git", "commit", "-q", "-m", "brew-unpack"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -134,13 +134,13 @@ module Homebrew
|
||||
world_writable = legacy_cache.stat.mode & 0777 == 0777
|
||||
return if world_writable
|
||||
return if legacy_cache.symlink?
|
||||
return if !legacy_cache.owned? && legacy_cache.lstat.uid != 0
|
||||
return if !legacy_cache.owned? && legacy_cache.lstat.uid.nonzero?
|
||||
|
||||
ohai "Migrating #{legacy_cache} to #{HOMEBREW_CACHE}..."
|
||||
HOMEBREW_CACHE.mkpath
|
||||
legacy_cache.cd do
|
||||
legacy_cache.entries.each do |f|
|
||||
next if [".", "..", ".migration_attempted"].include? "#{f}"
|
||||
next if [".", "..", ".migration_attempted"].include? f.to_s
|
||||
begin
|
||||
FileUtils.cp_r f, HOMEBREW_CACHE
|
||||
rescue
|
||||
@ -173,7 +173,7 @@ module Homebrew
|
||||
link_src_dst_dirs(HOMEBREW_REPOSITORY/"etc/bash_completion.d",
|
||||
HOMEBREW_PREFIX/"etc/bash_completion.d", command)
|
||||
link_src_dst_dirs(HOMEBREW_REPOSITORY/"share/doc/homebrew",
|
||||
HOMEBREW_PREFIX/"share/doc/homebrew", command, link_dir: true)
|
||||
HOMEBREW_PREFIX/"share/doc/homebrew", command, :link_dir => true)
|
||||
link_src_dst_dirs(HOMEBREW_REPOSITORY/"share/zsh/site-functions",
|
||||
HOMEBREW_PREFIX/"share/zsh/site-functions", command)
|
||||
link_path_manpages(HOMEBREW_REPOSITORY/"share", command)
|
||||
@ -359,10 +359,10 @@ class Reporter
|
||||
private
|
||||
|
||||
def repo_var
|
||||
@repo_var ||= tap.path.to_s.
|
||||
strip_prefix(Tap::TAP_DIRECTORY.to_s).
|
||||
tr("^A-Za-z0-9", "_").
|
||||
upcase
|
||||
@repo_var ||= tap.path.to_s
|
||||
.strip_prefix(Tap::TAP_DIRECTORY.to_s)
|
||||
.tr("^A-Za-z0-9", "_")
|
||||
.upcase
|
||||
end
|
||||
|
||||
def diff
|
||||
@ -387,7 +387,7 @@ class ReporterHub
|
||||
|
||||
def add(reporter)
|
||||
@reporters << reporter
|
||||
report = reporter.report.delete_if { |k,v| v.empty? }
|
||||
report = reporter.report.delete_if { |_k, v| v.empty? }
|
||||
@hash.update(report) { |_key, oldval, newval| oldval.concat(newval) }
|
||||
end
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
(ARGV.resolved_formulae - outdated).each do |f|
|
||||
versions = f.installed_kegs.map { |keg| keg.version }
|
||||
versions = f.installed_kegs.map(&:version)
|
||||
if versions.empty?
|
||||
onoe "#{f.full_name} not installed"
|
||||
else
|
||||
@ -51,11 +51,11 @@ module Homebrew
|
||||
outdated -= pinned
|
||||
end
|
||||
|
||||
unless outdated.empty?
|
||||
if outdated.empty?
|
||||
oh1 "No packages to upgrade"
|
||||
else
|
||||
oh1 "Upgrading #{outdated.length} outdated package#{plural(outdated.length)}, with result:"
|
||||
puts outdated.map { |f| "#{f.full_name} #{f.pkg_version}" } * ", "
|
||||
else
|
||||
oh1 "No packages to upgrade"
|
||||
end
|
||||
|
||||
unless upgrade_pinned? || pinned.empty?
|
||||
@ -116,6 +116,10 @@ module Homebrew
|
||||
ofail e
|
||||
ensure
|
||||
# restore previous installation state if build failed
|
||||
outdated_keg.link if outdated_keg && !f.installed? rescue nil
|
||||
begin
|
||||
outdated_keg.link if outdated_keg && !f.installed?
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -27,7 +27,7 @@ module Homebrew
|
||||
raise FormulaUnspecifiedError if ARGV.named.empty?
|
||||
|
||||
used_formulae = ARGV.formulae
|
||||
formulae = (ARGV.include? "--installed") ? Formula.installed : Formula
|
||||
formulae = ARGV.include?("--installed") ? Formula.installed : Formula
|
||||
recursive = ARGV.flag? "--recursive"
|
||||
includes = []
|
||||
ignores = []
|
||||
@ -65,8 +65,6 @@ module Homebrew
|
||||
Requirement.prune unless includes.include?("build?")
|
||||
end
|
||||
end
|
||||
deps.any? { |dep| dep.to_formula.full_name == ff.full_name rescue dep.name == ff.name } ||
|
||||
reqs.any? { |req| req.name == ff.name || [ff.name, ff.full_name].include?(req.default_formula) }
|
||||
else
|
||||
deps = f.deps.reject do |dep|
|
||||
ignores.any? { |ignore| dep.send(ignore) } && !includes.any? { |include| dep.send(include) }
|
||||
@ -74,8 +72,17 @@ module Homebrew
|
||||
reqs = f.requirements.reject do |req|
|
||||
ignores.any? { |ignore| req.send(ignore) } && !includes.any? { |include| req.send(include) }
|
||||
end
|
||||
deps.any? { |dep| dep.to_formula.full_name == ff.full_name rescue dep.name == ff.name } ||
|
||||
reqs.any? { |req| req.name == ff.name || [ff.name, ff.full_name].include?(req.default_formula) }
|
||||
end
|
||||
next true if deps.any? do |dep|
|
||||
begin
|
||||
dep.to_formula.full_name == ff.full_name
|
||||
rescue
|
||||
dep.name == ff.name
|
||||
end
|
||||
end
|
||||
|
||||
reqs.any? do |req|
|
||||
req.name == ff.name || [ff.name, ff.full_name].include?(req.default_formula)
|
||||
end
|
||||
rescue FormulaUnavailableError
|
||||
# Silently ignore this case as we don't care about things used in
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user