Merge pull request #910 from MikeMcQuaid/cmd-rubocop

Fix Library/Homebrew/cmd RuboCop warnings
This commit is contained in:
Mike McQuaid 2016-09-11 19:11:04 +01:00 committed by GitHub
commit ea0405c8dd
19 changed files with 94 additions and 83 deletions

View File

@ -41,22 +41,20 @@ module Homebrew
end end
def external_commands def external_commands
paths.reduce([]) do |cmds, path| paths.each_with_object([]) do |path, cmds|
Dir["#{path}/brew-*"].each do |file| Dir["#{path}/brew-*"].each do |file|
next unless File.executable?(file) next unless File.executable?(file)
cmd = File.basename(file, ".rb")[5..-1] cmd = File.basename(file, ".rb")[5..-1]
cmds << cmd unless cmd.include?(".") cmds << cmd unless cmd.include?(".")
end end
cmds
end.sort end.sort
end end
private private
def find_internal_commands(directory) 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 << f.basename.to_s.sub(/\.(?:rb|sh)$/, "") if f.file?
cmds
end end
end end
end end

View File

@ -26,14 +26,12 @@ module Homebrew
results.print results.print
elsif search_type.size > 1 elsif search_type.size > 1
odie "Pick one, and only one, of -s/--search, -n/--name, or -d/--description." odie "Pick one, and only one, of -s/--search, -n/--name, or -d/--description."
else elsif arg = ARGV.named.first
if arg = ARGV.named.first regex = Homebrew.query_regexp(arg)
regex = Homebrew::query_regexp(arg)
results = Descriptions.search(regex, search_type.first) results = Descriptions.search(regex, search_type.first)
results.print results.print
else else
odie "You must provide a search term." odie "You must provide a search term."
end end
end end
end
end end

View File

@ -40,7 +40,7 @@ module Homebrew
end end
out = checks.send(method) out = checks.send(method)
unless out.nil? || out.empty? next if out.nil? || out.empty?
if first_warning if first_warning
$stderr.puts <<-EOS.undent $stderr.puts <<-EOS.undent
#{Tty.white}Please note that these warnings are just used to help the Homebrew maintainers #{Tty.white}Please note that these warnings are just used to help the Homebrew maintainers
@ -54,7 +54,6 @@ module Homebrew
Homebrew.failed = true Homebrew.failed = true
first_warning = false first_warning = false
end end
end
puts "Your system is ready to brew." unless Homebrew.failed? puts "Your system is ready to brew." unless Homebrew.failed?
end end

View File

@ -56,13 +56,12 @@ module Homebrew
end end
end end
unless fetched_bottle next if fetched_bottle
fetch_formula(f) fetch_formula(f)
f.resources.each { |r| fetch_resource(r) } f.resources.each { |r| fetch_resource(r) }
f.patchlist.each { |p| fetch_patch(p) if p.external? } f.patchlist.each { |p| fetch_patch(p) if p.external? }
end end
end end
end
def fetch_bottle?(f) def fetch_bottle?(f)
return true if ARGV.force_bottle? && f.bottle return true if ARGV.force_bottle? && f.bottle

View File

@ -1,4 +1,4 @@
HOMEBREW_HELP = <<-EOS HOMEBREW_HELP = <<-EOS.freeze
Example usage: Example usage:
brew search [TEXT|/REGEX/] brew search [TEXT|/REGEX/]
brew (info|home|options) [FORMULA...] brew (info|home|options) [FORMULA...]
@ -78,11 +78,11 @@ module Homebrew
HOMEBREW_HELP HOMEBREW_HELP
else else
help_lines.map do |line| help_lines.map do |line|
line.slice(2..-1). line.slice(2..-1)
sub(/^ \* /, "#{Tty.highlight}brew#{Tty.reset} "). .sub(/^ \* /, "#{Tty.highlight}brew#{Tty.reset} ")
gsub(/`(.*?)`/, "#{Tty.highlight}\\1#{Tty.reset}"). .gsub(/`(.*?)`/, "#{Tty.highlight}\\1#{Tty.reset}")
gsub(/<(.*?)>/, "#{Tty.em}\\1#{Tty.reset}"). .gsub(/<(.*?)>/, "#{Tty.em}\\1#{Tty.reset}")
gsub("@hide_from_man_page", "") .gsub("@hide_from_man_page", "")
end.join.strip end.join.strip
end end
end end

View File

@ -45,7 +45,7 @@ module Homebrew
end end
else else
ARGV.named.each_with_index do |f, i| ARGV.named.each_with_index do |f, i|
puts unless i == 0 puts unless i.zero?
begin begin
if f.include?("/") || File.exist?(f) if f.include?("/") || File.exist?(f)
info_formula Formulary.factory(f) info_formula Formulary.factory(f)

View File

@ -71,13 +71,16 @@ module Homebrew
raise "Specify `--HEAD` in uppercase to build from trunk." raise "Specify `--HEAD` in uppercase to build from trunk."
end end
unless ARGV.force?
ARGV.named.each do |name| ARGV.named.each do |name|
if !File.exist?(name) && next if File.exist?(name)
(name =~ HOMEBREW_TAP_FORMULA_REGEX || name =~ HOMEBREW_CASK_TAP_FORMULA_REGEX) if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_FORMULA_REGEX
next
end
tap = Tap.fetch($1, $2) tap = Tap.fetch($1, $2)
tap.install unless tap.installed? tap.install unless tap.installed?
end end
end unless ARGV.force? end
begin begin
formulae = [] formulae = []

View File

@ -29,7 +29,7 @@ module Homebrew
# Unbrewed uses the PREFIX, which will exist # Unbrewed uses the PREFIX, which will exist
# Things below use the CELLAR, which doesn't until the first formula is installed. # Things below use the CELLAR, which doesn't until the first formula is installed.
unless HOMEBREW_CELLAR.exist? unless HOMEBREW_CELLAR.exist?
raise NoSuchKegError.new(ARGV.named.first) unless ARGV.named.empty? raise NoSuchKegError, ARGV.named.first unless ARGV.named.empty?
return return
end end
@ -60,7 +60,7 @@ module Homebrew
private private
UNBREWED_EXCLUDE_FILES = %w[.DS_Store] UNBREWED_EXCLUDE_FILES = %w[.DS_Store].freeze
UNBREWED_EXCLUDE_PATHS = %w[ UNBREWED_EXCLUDE_PATHS = %w[
.github/* .github/*
bin/brew bin/brew
@ -80,7 +80,7 @@ module Homebrew
share/man/man1/brew.1 share/man/man1/brew.1
share/man/whatis share/man/whatis
share/zsh/site-functions/_brew share/zsh/site-functions/_brew
] ].freeze
def list_unbrewed def list_unbrewed
dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s } dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s }
@ -117,7 +117,7 @@ module Homebrew
end end
end end
pinned_versions.each do |d, version| 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 end
else # --versions without --pinned else # --versions without --pinned
names.each do |d| names.each do |d|

View File

@ -18,7 +18,7 @@ module Homebrew
private private
def git_log(path=nil) def git_log(path = nil)
if File.exist? "#{`git rev-parse --show-toplevel`.chomp}/.git/shallow" if File.exist? "#{`git rev-parse --show-toplevel`.chomp}/.git/shallow"
opoo <<-EOS.undent opoo <<-EOS.undent
The git repository is a shallow clone therefore the filtering may be incorrect. The git repository is a shallow clone therefore the filtering may be incorrect.

View File

@ -18,7 +18,7 @@ module Homebrew
Diagnostic.missing_deps(ff) do |name, missing| Diagnostic.missing_deps(ff) do |name, missing|
print "#{name}: " if ff.size > 1 print "#{name}: " if ff.size > 1
puts "#{missing * " "}" puts (missing * " ").to_s
end end
end end
end end

View File

@ -47,6 +47,7 @@ module Homebrew
end end
end end
unless ARGV.dry_run?
if ObserverPathnameExtension.total.zero? if ObserverPathnameExtension.total.zero?
puts "Nothing pruned" if ARGV.verbose? puts "Nothing pruned" if ARGV.verbose?
else else
@ -54,7 +55,8 @@ module Homebrew
print "Pruned #{n} symbolic links " print "Pruned #{n} symbolic links "
print "and #{d} directories " if d > 0 print "and #{d} directories " if d > 0
puts "from #{HOMEBREW_PREFIX}" puts "from #{HOMEBREW_PREFIX}"
end unless ARGV.dry_run? end
end
unlinkapps_prune(:dry_run => ARGV.dry_run?, :quiet => true) unlinkapps_prune(:dry_run => ARGV.dry_run?, :quiet => true)
end end

View File

@ -71,7 +71,7 @@ module Homebrew
puts puts
end end
puts msg puts msg
elsif count == 0 elsif count.zero?
puts "No formula found for #{query.inspect}." puts "No formula found for #{query.inspect}."
begin begin
GitHub.print_pull_requests_matching(query) GitHub.print_pull_requests_matching(query)
@ -100,7 +100,7 @@ module Homebrew
SEARCHABLE_TAPS = OFFICIAL_TAPS.map { |tap| ["Homebrew", tap] } + [ SEARCHABLE_TAPS = OFFICIAL_TAPS.map { |tap| ["Homebrew", tap] } + [
%w[Caskroom cask], %w[Caskroom cask],
%w[Caskroom versions] %w[Caskroom versions],
] ]
def query_regexp(query) def query_regexp(query)
@ -151,7 +151,7 @@ module Homebrew
names = remote_tap_formulae["#{user}/#{repo}"] names = remote_tap_formulae["#{user}/#{repo}"]
user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization
names.select { |name| rx === name }.map { |name| "#{user}/#{repo}/#{name}" } 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`" opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
[] []
rescue GitHub::Error => e rescue GitHub::Error => e

View File

@ -59,7 +59,7 @@ module Homebrew
puts info puts info
else else
taps.each_with_index do |tap, i| taps.each_with_index do |tap, i|
puts unless i == 0 puts unless i.zero?
info = "#{tap}: " info = "#{tap}: "
if tap.installed? if tap.installed?
info += tap.pinned? ? "pinned" : "unpinned" info += tap.pinned? ? "pinned" : "unpinned"
@ -70,7 +70,7 @@ module Homebrew
if (command_count = tap.command_files.size) > 0 if (command_count = tap.command_files.size) > 0
info += ", #{command_count} command#{plural(command_count)}" info += ", #{command_count} command#{plural(command_count)}"
end 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 += "\n#{tap.path} (#{tap.path.abv})"
info += "\nFrom: #{tap.remote.nil? ? "N/A" : tap.remote}" info += "\nFrom: #{tap.remote.nil? ? "N/A" : tap.remote}"
else else

View File

@ -60,6 +60,8 @@ module Homebrew
end end
def rm_pin(rack) def rm_pin(rack)
Formulary.from_rack(rack).unpin rescue nil Formulary.from_rack(rack).unpin
rescue
nil
end end
end end

View File

@ -65,7 +65,7 @@ module Homebrew
def unlinkapps_unlink?(target_app, opts = {}) def unlinkapps_unlink?(target_app, opts = {})
# Skip non-symlinks and symlinks that don't point into the Homebrew prefix. # 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) return false unless app && app.start_with?(*UNLINKAPPS_PREFIXES)
if opts.fetch(:prune, false) if opts.fetch(:prune, false)

View File

@ -43,7 +43,7 @@ module Homebrew
end end
ENV["VERBOSE"] = nil ENV["VERBOSE"] = nil
if ARGV.git? next unless ARGV.git?
ohai "Setting up git repository" ohai "Setting up git repository"
cd stage_dir cd stage_dir
system "git", "init", "-q" system "git", "init", "-q"
@ -51,5 +51,4 @@ module Homebrew
system "git", "commit", "-q", "-m", "brew-unpack" system "git", "commit", "-q", "-m", "brew-unpack"
end end
end end
end
end end

View File

@ -134,13 +134,13 @@ module Homebrew
world_writable = legacy_cache.stat.mode & 0777 == 0777 world_writable = legacy_cache.stat.mode & 0777 == 0777
return if world_writable return if world_writable
return if legacy_cache.symlink? 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}..." ohai "Migrating #{legacy_cache} to #{HOMEBREW_CACHE}..."
HOMEBREW_CACHE.mkpath HOMEBREW_CACHE.mkpath
legacy_cache.cd do legacy_cache.cd do
legacy_cache.entries.each do |f| legacy_cache.entries.each do |f|
next if [".", "..", ".migration_attempted"].include? "#{f}" next if [".", "..", ".migration_attempted"].include? f.to_s
begin begin
FileUtils.cp_r f, HOMEBREW_CACHE FileUtils.cp_r f, HOMEBREW_CACHE
rescue rescue
@ -173,7 +173,7 @@ module Homebrew
link_src_dst_dirs(HOMEBREW_REPOSITORY/"etc/bash_completion.d", link_src_dst_dirs(HOMEBREW_REPOSITORY/"etc/bash_completion.d",
HOMEBREW_PREFIX/"etc/bash_completion.d", command) HOMEBREW_PREFIX/"etc/bash_completion.d", command)
link_src_dst_dirs(HOMEBREW_REPOSITORY/"share/doc/homebrew", 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", link_src_dst_dirs(HOMEBREW_REPOSITORY/"share/zsh/site-functions",
HOMEBREW_PREFIX/"share/zsh/site-functions", command) HOMEBREW_PREFIX/"share/zsh/site-functions", command)
link_path_manpages(HOMEBREW_REPOSITORY/"share", command) link_path_manpages(HOMEBREW_REPOSITORY/"share", command)
@ -359,10 +359,10 @@ class Reporter
private private
def repo_var def repo_var
@repo_var ||= tap.path.to_s. @repo_var ||= tap.path.to_s
strip_prefix(Tap::TAP_DIRECTORY.to_s). .strip_prefix(Tap::TAP_DIRECTORY.to_s)
tr("^A-Za-z0-9", "_"). .tr("^A-Za-z0-9", "_")
upcase .upcase
end end
def diff def diff
@ -387,7 +387,7 @@ class ReporterHub
def add(reporter) def add(reporter)
@reporters << 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) } @hash.update(report) { |_key, oldval, newval| oldval.concat(newval) }
end end

View File

@ -35,7 +35,7 @@ module Homebrew
end end
(ARGV.resolved_formulae - outdated).each do |f| (ARGV.resolved_formulae - outdated).each do |f|
versions = f.installed_kegs.map { |keg| keg.version } versions = f.installed_kegs.map(&:version)
if versions.empty? if versions.empty?
onoe "#{f.full_name} not installed" onoe "#{f.full_name} not installed"
else else
@ -51,11 +51,11 @@ module Homebrew
outdated -= pinned outdated -= pinned
end end
unless outdated.empty? if outdated.empty?
oh1 "No packages to upgrade"
else
oh1 "Upgrading #{outdated.length} outdated package#{plural(outdated.length)}, with result:" oh1 "Upgrading #{outdated.length} outdated package#{plural(outdated.length)}, with result:"
puts outdated.map { |f| "#{f.full_name} #{f.pkg_version}" } * ", " puts outdated.map { |f| "#{f.full_name} #{f.pkg_version}" } * ", "
else
oh1 "No packages to upgrade"
end end
unless upgrade_pinned? || pinned.empty? unless upgrade_pinned? || pinned.empty?
@ -116,6 +116,10 @@ module Homebrew
ofail e ofail e
ensure ensure
# restore previous installation state if build failed # 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
end end

View File

@ -27,7 +27,7 @@ module Homebrew
raise FormulaUnspecifiedError if ARGV.named.empty? raise FormulaUnspecifiedError if ARGV.named.empty?
used_formulae = ARGV.formulae used_formulae = ARGV.formulae
formulae = (ARGV.include? "--installed") ? Formula.installed : Formula formulae = ARGV.include?("--installed") ? Formula.installed : Formula
recursive = ARGV.flag? "--recursive" recursive = ARGV.flag? "--recursive"
includes = [] includes = []
ignores = [] ignores = []
@ -65,8 +65,6 @@ module Homebrew
Requirement.prune unless includes.include?("build?") Requirement.prune unless includes.include?("build?")
end end
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 else
deps = f.deps.reject do |dep| deps = f.deps.reject do |dep|
ignores.any? { |ignore| dep.send(ignore) } && !includes.any? { |include| dep.send(include) } ignores.any? { |ignore| dep.send(ignore) } && !includes.any? { |include| dep.send(include) }
@ -74,8 +72,17 @@ module Homebrew
reqs = f.requirements.reject do |req| reqs = f.requirements.reject do |req|
ignores.any? { |ignore| req.send(ignore) } && !includes.any? { |include| req.send(include) } ignores.any? { |ignore| req.send(ignore) } && !includes.any? { |include| req.send(include) }
end end
deps.any? { |dep| dep.to_formula.full_name == ff.full_name rescue dep.name == ff.name } || end
reqs.any? { |req| req.name == ff.name || [ff.name, ff.full_name].include?(req.default_formula) } 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 end
rescue FormulaUnavailableError rescue FormulaUnavailableError
# Silently ignore this case as we don't care about things used in # Silently ignore this case as we don't care about things used in