aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
diff options
context:
space:
mode:
authorMike McQuaid2016-09-11 19:11:04 +0100
committerGitHub2016-09-11 19:11:04 +0100
commitea0405c8dd0e591ca570b834cd5f0a76e3ee1a90 (patch)
treedf89bd41d536d9f8f6a966beaf204e124e590f3d /Library/Homebrew/cmd
parent8448fe17cba78e35a260d4c4e0189abe7ab75fcf (diff)
parent1174264d47b03bbcdb6900896b2a512c05686549 (diff)
downloadbrew-ea0405c8dd0e591ca570b834cd5f0a76e3ee1a90.tar.bz2
Merge pull request #910 from MikeMcQuaid/cmd-rubocop
Fix Library/Homebrew/cmd RuboCop warnings
Diffstat (limited to 'Library/Homebrew/cmd')
-rw-r--r--Library/Homebrew/cmd/commands.rb6
-rw-r--r--Library/Homebrew/cmd/desc.rb12
-rw-r--r--Library/Homebrew/cmd/doctor.rb19
-rw-r--r--Library/Homebrew/cmd/fetch.rb9
-rw-r--r--Library/Homebrew/cmd/help.rb12
-rw-r--r--Library/Homebrew/cmd/info.rb2
-rw-r--r--Library/Homebrew/cmd/install.rb11
-rw-r--r--Library/Homebrew/cmd/list.rb8
-rw-r--r--Library/Homebrew/cmd/log.rb2
-rw-r--r--Library/Homebrew/cmd/missing.rb2
-rw-r--r--Library/Homebrew/cmd/prune.rb18
-rw-r--r--Library/Homebrew/cmd/search.rb6
-rw-r--r--Library/Homebrew/cmd/tap-info.rb4
-rw-r--r--Library/Homebrew/cmd/uninstall.rb4
-rw-r--r--Library/Homebrew/cmd/unlinkapps.rb2
-rw-r--r--Library/Homebrew/cmd/unpack.rb13
-rw-r--r--Library/Homebrew/cmd/update-report.rb16
-rw-r--r--Library/Homebrew/cmd/upgrade.rb14
-rw-r--r--Library/Homebrew/cmd/uses.rb17
19 files changed, 94 insertions, 83 deletions
diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb
index b8407d668..87dca8e79 100644
--- a/Library/Homebrew/cmd/commands.rb
+++ b/Library/Homebrew/cmd/commands.rb
@@ -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
diff --git a/Library/Homebrew/cmd/desc.rb b/Library/Homebrew/cmd/desc.rb
index e7e7528fc..9bb737e40 100644
--- a/Library/Homebrew/cmd/desc.rb
+++ b/Library/Homebrew/cmd/desc.rb
@@ -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
diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb
index f6d5d8d4c..8dd78bf1a 100644
--- a/Library/Homebrew/cmd/doctor.rb
+++ b/Library/Homebrew/cmd/doctor.rb
@@ -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?
diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb
index 249f00faf..fd8b0780c 100644
--- a/Library/Homebrew/cmd/fetch.rb
+++ b/Library/Homebrew/cmd/fetch.rb
@@ -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
diff --git a/Library/Homebrew/cmd/help.rb b/Library/Homebrew/cmd/help.rb
index 1456becb2..0bf3d0d8d 100644
--- a/Library/Homebrew/cmd/help.rb
+++ b/Library/Homebrew/cmd/help.rb
@@ -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
diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb
index 7c483c378..0310ab624 100644
--- a/Library/Homebrew/cmd/info.rb
+++ b/Library/Homebrew/cmd/info.rb
@@ -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)
diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb
index 074f5fbc3..99cb75353 100644
--- a/Library/Homebrew/cmd/install.rb
+++ b/Library/Homebrew/cmd/install.rb
@@ -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 = []
diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb
index 80576033a..9d5de74cc 100644
--- a/Library/Homebrew/cmd/list.rb
+++ b/Library/Homebrew/cmd/list.rb
@@ -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|
diff --git a/Library/Homebrew/cmd/log.rb b/Library/Homebrew/cmd/log.rb
index a07107170..9492c1e1e 100644
--- a/Library/Homebrew/cmd/log.rb
+++ b/Library/Homebrew/cmd/log.rb
@@ -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.
diff --git a/Library/Homebrew/cmd/missing.rb b/Library/Homebrew/cmd/missing.rb
index 181530562..bbd514223 100644
--- a/Library/Homebrew/cmd/missing.rb
+++ b/Library/Homebrew/cmd/missing.rb
@@ -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
diff --git a/Library/Homebrew/cmd/prune.rb b/Library/Homebrew/cmd/prune.rb
index a36c960e7..20c2a3454 100644
--- a/Library/Homebrew/cmd/prune.rb
+++ b/Library/Homebrew/cmd/prune.rb
@@ -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
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index 2a100083d..50d9f5f74 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -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
diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb
index 6070a3098..b599cb591 100644
--- a/Library/Homebrew/cmd/tap-info.rb
+++ b/Library/Homebrew/cmd/tap-info.rb
@@ -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
diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb
index 62092376d..6ea45a770 100644
--- a/Library/Homebrew/cmd/uninstall.rb
+++ b/Library/Homebrew/cmd/uninstall.rb
@@ -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
diff --git a/Library/Homebrew/cmd/unlinkapps.rb b/Library/Homebrew/cmd/unlinkapps.rb
index ba21eed62..44b8aa06c 100644
--- a/Library/Homebrew/cmd/unlinkapps.rb
+++ b/Library/Homebrew/cmd/unlinkapps.rb
@@ -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)
diff --git a/Library/Homebrew/cmd/unpack.rb b/Library/Homebrew/cmd/unpack.rb
index f0d7a555b..a8c7c36a6 100644
--- a/Library/Homebrew/cmd/unpack.rb
+++ b/Library/Homebrew/cmd/unpack.rb
@@ -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
diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb
index 8baae878c..c068d02ee 100644
--- a/Library/Homebrew/cmd/update-report.rb
+++ b/Library/Homebrew/cmd/update-report.rb
@@ -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
diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb
index d0fa180ce..1053319bf 100644
--- a/Library/Homebrew/cmd/upgrade.rb
+++ b/Library/Homebrew/cmd/upgrade.rb
@@ -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
diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb
index ff7f7529e..79b57eb23 100644
--- a/Library/Homebrew/cmd/uses.rb
+++ b/Library/Homebrew/cmd/uses.rb
@@ -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