language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
Homebrew
brew
65fdfefc99e2308a406e57eb55cd2e32f107717f.json
Add `language_eval` method.
Library/Homebrew/cask/lib/hbc/cask.rb
@@ -11,7 +11,10 @@ def initialize(token, sourcefile_path: nil, dsl: nil, &block) @token = token @sourcefile_path = sourcefile_path @dsl = dsl || DSL.new(@token) - @dsl.instance_eval(&block) if block_given? + if block_given? + @dsl.instance_eval(&block) + @dsl.language_eval + end end DSL::DSL_METHODS.each do |method_name|
true
Other
Homebrew
brew
65fdfefc99e2308a406e57eb55cd2e32f107717f.json
Add `language_eval` method.
Library/Homebrew/cask/lib/hbc/dsl.rb
@@ -100,30 +100,31 @@ def homepage(homepage = nil) end def language(*args, &block) - @language ||= {} - if !args.empty? && block_given? args.each do |arg| MacOS.languages.each_with_index do |l, index| string_or_regex = arg == :default ? %r{^en} : arg next unless l.match(string_or_regex) - next unless @language[:level].nil? || @language[:level] > index + next unless @language.nil? || @language[:level].nil? || @language[:level] > index @language = { block: block, level: index, } end end - - if args.include?(:default) - # :default has to be the last language block in order to assign return value of the selected `language` block to `@language` - @language = @language[:block].call - end else + language_eval @language end end + + def language_eval + if @language.is_a?(Hash) && @language.key?(:block) + @language = @language[:block].call + end + end + def url(*args, &block) url_given = !args.empty? || block_given? return @url unless url_given
true
Other
Homebrew
brew
929c594f41437f3a0a6d13fed2d596a0ba60435b.json
Add test for `MacOS.languages`.
Library/Homebrew/test/test_os_mac_language.rb
@@ -2,7 +2,15 @@ require "os/mac" class OSMacLanguageTests < Homebrew::TestCase + LANGUAGE_REGEX = /\A[a-z]{2}(-[A-Z]{2})?(-[A-Z][a-z]{3})?\Z/ + + def test_languages_format + OS::Mac.languages.each do |language| + assert_match LANGUAGE_REGEX, language + end + end + def test_language_format - assert_match(/\A[a-z]{2}(-[A-Z]{2})?\Z/, OS::Mac.language) + assert_match LANGUAGE_REGEX, OS::Mac.language end end
false
Other
Homebrew
brew
e4da2dfb9f49349251b51e80be57d2a70c979321.json
Make test for “cask already installed” less strict.
Library/Homebrew/cask/test/cask/cli/install_test.rb
@@ -29,7 +29,7 @@ TestHelper.must_output(self, lambda { Hbc::CLI::Install.run("local-transmission", "") - }, %r{Warning: A Cask for local-transmission is already installed. Add the "--force" option to force re-install.}) + }, %r{Warning: A Cask for local-transmission is already installed.}) end it "allows double install with --force" do
false
Other
Homebrew
brew
4f1ef16cbf09fc1b98143ff672859dcefda00e1b.json
Fix indentation of CaskCommandFailedError.
Library/Homebrew/cask/lib/hbc/exceptions.rb
@@ -65,21 +65,19 @@ def initialize(cmd, stdout, stderr, status) end def to_s - <<-EOS - Command failed to execute! - - ==> Failed command: - #{@cmd} - - ==> Standard Output of failed command: - #{@stdout} - - ==> Standard Error of failed command: - #{@stderr} - - ==> Exit status of failed command: - #{@status.inspect} - EOS + s = "Command failed to execute!\n" + s.concat("\n") + s.concat("==> Failed command:\n") + s.concat(@cmd).concat("\n") + s.concat("\n") + s.concat("==> Standard Output of failed command:\n") + s.concat(@stdout).concat("\n") + s.concat("\n") + s.concat("==> Standard Error of failed command:\n") + s.concat(@stderr).concat("\n") + s.concat("\n") + s.concat("==> Exit status of failed command:\n") + s.concat(@status.inspect).concat("\n") end end
false
Other
Homebrew
brew
8eac5314f68cbe3f99ed92a2dc6472f7546b188c.json
Add official external commands to manpage. These are the ones that are auto-installed without tapping and it makes sense to make them more prominent in our documentation as we've offloaded various functionality over the years to each of them.
Library/Homebrew/manpages/brew.1.md.erb
@@ -54,7 +54,21 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note <%= developer_commands.join("\n") %> -## EXTERNAL COMMANDS +## OFFICIAL EXTERNAL COMMANDS + + * `bundle`: + Bundler for non-Ruby dependencies from Homebrew: + <https://github.com/Homebrew/homebrew-bundle> + + * `cask`: + Install macOS applications distributed as binaries: + <https://github.com/caskroom/homebrew-cask> + + * `services`: + Integrates Homebrew formulae with macOS's `launchctl` manager: + <https://github.com/Homebrew/homebrew-services> + +## CUSTOM EXTERNAL COMMANDS Homebrew, like `git`(1), supports external commands. These are executable scripts that reside somewhere in the `PATH`, named `brew-`<cmdname> or @@ -251,7 +265,7 @@ If your proxy requires authentication: Homebrew Documentation: <https://github.com/Homebrew/brew/blob/master/docs/> -`git`(1), `git-log`(1) +`brew-cask`(1), `git`(1), `git-log`(1) ## AUTHORS
true
Other
Homebrew
brew
8eac5314f68cbe3f99ed92a2dc6472f7546b188c.json
Add official external commands to manpage. These are the ones that are auto-installed without tapping and it makes sense to make them more prominent in our documentation as we've offloaded various functionality over the years to each of them.
docs/brew.1.html
@@ -601,7 +601,19 @@ <h2 id="DEVELOPER-COMMANDS">DEVELOPER COMMANDS</h2> </dl> -<h2 id="EXTERNAL-COMMANDS">EXTERNAL COMMANDS</h2> +<h2 id="OFFICIAL-EXTERNAL-COMMANDS">OFFICIAL EXTERNAL COMMANDS</h2> + +<dl> +<dt class="flush"><code>bundle</code></dt><dd><p>Bundler for non-Ruby dependencies from Homebrew: +<a href="https://github.com/Homebrew/homebrew-bundle" data-bare-link="true">https://github.com/Homebrew/homebrew-bundle</a></p></dd> +<dt class="flush"><code>cask</code></dt><dd><p>Install macOS applications distributed as binaries: +<a href="https://github.com/caskroom/homebrew-cask" data-bare-link="true">https://github.com/caskroom/homebrew-cask</a></p></dd> +<dt><code>services</code></dt><dd><p>Integrates Homebrew formulae with macOS's <code>launchctl</code> manager: +<a href="https://github.com/Homebrew/homebrew-services" data-bare-link="true">https://github.com/Homebrew/homebrew-services</a></p></dd> +</dl> + + +<h2 id="CUSTOM-EXTERNAL-COMMANDS">CUSTOM EXTERNAL COMMANDS</h2> <p>Homebrew, like <code>git</code>(1), supports external commands. These are executable scripts that reside somewhere in the <code>PATH</code>, named <code>brew-</code><var>cmdname</var> or @@ -742,7 +754,7 @@ <h2 id="SEE-ALSO">SEE ALSO</h2> <p>Homebrew Documentation: <a href="https://github.com/Homebrew/brew/blob/master/docs/" data-bare-link="true">https://github.com/Homebrew/brew/blob/master/docs/</a></p> -<p><code>git</code>(1), <code>git-log</code>(1)</p> +<p><code>brew-cask</code>(1), <code>git</code>(1), <code>git-log</code>(1)</p> <h2 id="AUTHORS">AUTHORS</h2>
true
Other
Homebrew
brew
8eac5314f68cbe3f99ed92a2dc6472f7546b188c.json
Add official external commands to manpage. These are the ones that are auto-installed without tapping and it makes sense to make them more prominent in our documentation as we've offloaded various functionality over the years to each of them.
manpages/brew.1
@@ -801,7 +801,21 @@ If \fB\-\-to\-tag\fR is passed, set HOMEBREW_UPDATE_TO_TAG to test updating betw .IP If \fB\-\-keep\-tmp\fR is passed, retain the temporary directory containing the new repository clone\. . -.SH "EXTERNAL COMMANDS" +.SH "OFFICIAL EXTERNAL COMMANDS" +. +.TP +\fBbundle\fR +Bundler for non\-Ruby dependencies from Homebrew: \fIhttps://github\.com/Homebrew/homebrew\-bundle\fR +. +.TP +\fBcask\fR +Install macOS applications distributed as binaries: \fIhttps://github\.com/caskroom/homebrew\-cask\fR +. +.TP +\fBservices\fR +Integrates Homebrew formulae with macOS\'s \fBlaunchctl\fR manager: \fIhttps://github\.com/Homebrew/homebrew\-services\fR +. +.SH "CUSTOM EXTERNAL COMMANDS" Homebrew, like \fBgit\fR(1), supports external commands\. These are executable scripts that reside somewhere in the \fBPATH\fR, named \fBbrew\-\fR\fIcmdname\fR or \fBbrew\-\fR\fIcmdname\fR\fB\.rb\fR, which can be invoked like \fBbrew\fR \fIcmdname\fR\. This allows you to create your own commands without modifying Homebrew\'s internals\. . .P @@ -1007,7 +1021,7 @@ http_proxy=http://<user>:<password>@<host>:<port> brew install foo Homebrew Documentation: \fIhttps://github\.com/Homebrew/brew/blob/master/docs/\fR . .P -\fBgit\fR(1), \fBgit\-log\fR(1) +\fBbrew\-cask\fR(1), \fBgit\fR(1), \fBgit\-log\fR(1) . .SH "AUTHORS" Homebrew\'s lead maintainer is Mike McQuaid\.
true
Other
Homebrew
brew
db478fb7b2d8047403b71208af73b400bcf7a3e2.json
list: fix exit code for --verbose and --pinned `brew list --verbose <formulae>` lists only those kegs that are installed and exits with 0 if all <formulae> installed. If one or more formulae from <formulae> are not installed, the command lists only installed versions and exits with 1. `brew --pinned formula` exits with 1 if formula is not pinned. Fixes #1172
Library/Homebrew/cmd/list.rb
@@ -106,7 +106,11 @@ def filtered_list names = if ARGV.named.empty? Formula.racks else - ARGV.named.map { |n| HOMEBREW_CELLAR+n }.select(&:exist?) + racks = ARGV.named.map { |n| HOMEBREW_CELLAR+n } + racks.select do |rack| + Homebrew.failed = true unless rack.exist? + rack.exist? + end end if ARGV.include? "--pinned" pinned_versions = {}
false
Other
Homebrew
brew
acaee035dfddd1fd90b883f19cb2c9f52852c2f3.json
Add compatibility layer for `module Homebrew`.
Library/Homebrew/compat.rb
@@ -2,6 +2,7 @@ require "compat/tap" require "compat/formula" require "compat/formula_specialties" +require "compat/global" require "compat/hardware" require "compat/macos" require "compat/md5"
true
Other
Homebrew
brew
acaee035dfddd1fd90b883f19cb2c9f52852c2f3.json
Add compatibility layer for `module Homebrew`.
Library/Homebrew/compat/global.rb
@@ -0,0 +1,16 @@ +module Homebrew + module_function + + def method_missing(method, *args, &block) + if instance_methods.include?(method) + # odeprecated "#{self}##{method}", "'module_function' or 'def self.#{method}' to convert it to a class method" + return instance_method(method).bind(self).call(*args, &block) + end + super + end + + def respond_to_missing?(method, include_private = false) + return true if method_defined?(method) + super(method, include_private) + end +end
true
Other
Homebrew
brew
884b26850615d5624e09762e1ae8bc5b104a934a.json
Use Formatter for all URLs.
Library/Homebrew/blacklist.rb
@@ -16,15 +16,15 @@ def blacklisted?(name) Homebrew provides pip via: `brew install python`. However you will then have two Pythons installed on your Mac, so alternatively you can install pip via the instructions at: - https://pip.readthedocs.io/en/stable/installing/ + #{Formatter.url("https://pip.readthedocs.io/en/stable/installing/")} EOS when "pil" then <<-EOS.undent Instead of PIL, consider `pip install pillow` or `brew install Homebrew/python/pillow`. EOS when "macruby" then <<-EOS.undent MacRuby is not packaged and is on an indefinite development hiatus. You can read more about it at: - https://github.com/MacRuby/MacRuby + #{Formatter.url("https://github.com/MacRuby/MacRuby")} EOS when /(lib)?lzma/ "lzma is now part of the xz formula." @@ -50,7 +50,7 @@ def blacklisted?(name) To install Clojure you should install Leiningen: brew install leiningen and then follow the tutorial: - https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md + #{Formatter.url("https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md")} EOS when "osmium" then <<-EOS.undent The creator of Osmium requests that it not be packaged and that people @@ -65,8 +65,8 @@ def blacklisted?(name) brew install typesafe-activator You can read more about this change at: - https://www.playframework.com/documentation/2.3.x/Migration23 - https://www.playframework.com/documentation/2.3.x/Highlights23 + #{Formatter.url("https://www.playframework.com/documentation/2.3.x/Migration23")} + #{Formatter.url("https://www.playframework.com/documentation/2.3.x/Highlights23")} EOS when "haskell-platform" then <<-EOS.undent We no longer package haskell-platform. Consider installing ghc
true
Other
Homebrew
brew
884b26850615d5624e09762e1ae8bc5b104a934a.json
Use Formatter for all URLs.
Library/Homebrew/cask/lib/hbc/dsl/caveats.rb
@@ -102,12 +102,12 @@ def malware(radar_number) A report has been made to Apple about this app. Their certificate will hopefully be revoked. See the public report at - https://openradar.appspot.com/#{radar_number} + #{Formatter.url("https://openradar.appspot.com/#{radar_number}")} If this report is accurate, please duplicate it at - https://bugreport.apple.com/ + #{Formatter.url("https://bugreport.apple.com/")} If this report is a mistake, please let us know by opening an issue at - https://github.com/caskroom/homebrew-cask/issues/new + #{Formatter.url("https://github.com/caskroom/homebrew-cask/issues/new")} EOS end
true
Other
Homebrew
brew
884b26850615d5624e09762e1ae8bc5b104a934a.json
Use Formatter for all URLs.
Library/Homebrew/cmd/help.rb
@@ -78,11 +78,12 @@ def command_help(path) HOMEBREW_HELP else help_lines.map do |line| - line.slice(2..-1). - sub(/^ \* /, "#{Tty.bold}brew#{Tty.reset} "). - gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}"). - gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}"). - gsub("@hide_from_man_page", "") + line.slice(2..-1) + .sub(/^ \* /, "#{Tty.bold}brew#{Tty.reset} ") + .gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}") + .gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) } + .gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}") + .gsub("@hide_from_man_page", "") end.join.strip end end
true
Other
Homebrew
brew
884b26850615d5624e09762e1ae8bc5b104a934a.json
Use Formatter for all URLs.
Library/Homebrew/cmd/update-report.rb
@@ -288,7 +288,7 @@ def migrate_legacy_repository_if_necessary Please try to resolve this error yourself and then run `brew update` again to complete the migration. If you need help please +1 an existing error or comment with your new error in issue: - #{Tty.em}https://github.com/Homebrew/brew/issues/987#{Tty.reset} + #{Formatter.url("https://github.com/Homebrew/brew/issues/987")} EOS $stderr.puts e.backtrace end
true
Other
Homebrew
brew
884b26850615d5624e09762e1ae8bc5b104a934a.json
Use Formatter for all URLs.
Library/Homebrew/diagnostic.rb
@@ -473,7 +473,7 @@ def check_user_curlrc If you have trouble downloading packages with Homebrew, then maybe this is the problem? If the following command doesn't work, then try removing your curlrc: - curl https://github.com + curl #{Formatter.url("https://github.com")} EOS end @@ -610,7 +610,7 @@ def check_dyld_vars Setting DYLD_INSERT_LIBRARIES can cause Go builds to fail. Having this set is common if you use this software: - http://asepsis.binaryage.com/ + #{Formatter.url("http://asepsis.binaryage.com/")} EOS end @@ -752,7 +752,7 @@ def check_git_origin Without a correctly configured origin, Homebrew won't update properly. You can solve this by adding the Homebrew remote: cd #{HOMEBREW_REPOSITORY} - git remote add origin https://github.com/Homebrew/brew.git + git remote add origin #{Formatter.url("https://github.com/Homebrew/brew.git")} EOS elsif origin !~ %r{Homebrew/brew(\.git)?$} <<-EOS.undent @@ -764,7 +764,7 @@ def check_git_origin Unless you have compelling reasons, consider setting the origin remote to point at the main repository, located at: - https://github.com/Homebrew/brew.git + #{Formatter.url("https://github.com/Homebrew/brew.git")} EOS end end @@ -956,8 +956,8 @@ def check_for_pydistutils_cfg_in_home <<-EOS.undent A .pydistutils.cfg file was found in $HOME, which may cause Python builds to fail. See: - https://bugs.python.org/issue6138 - https://bugs.python.org/issue4655 + #{Formatter.url("https://bugs.python.org/issue6138")} + #{Formatter.url("https://bugs.python.org/issue4655")} EOS end
true
Other
Homebrew
brew
884b26850615d5624e09762e1ae8bc5b104a934a.json
Use Formatter for all URLs.
Library/Homebrew/exceptions.rb
@@ -318,7 +318,7 @@ def fetch_issues def dump if !ARGV.verbose? puts - puts Formatter.error("READ THIS: #{Formatter.url(OS::ISSUES_URL)}") + puts Formatter.error(Formatter.url(OS::ISSUES_URL), label: "READ THIS") if formula.tap case formula.tap.name when "homebrew/boneyard" @@ -327,7 +327,7 @@ def dump else if issues_url = formula.tap.issues_url puts "If reporting this issue please do so at (not Homebrew/brew):" - puts " #{issues_url}" + puts " #{Formatter.url(issues_url)}" end end end
true
Other
Homebrew
brew
884b26850615d5624e09762e1ae8bc5b104a934a.json
Use Formatter for all URLs.
Library/Homebrew/requirements.rb
@@ -44,7 +44,7 @@ def message EOS else message + <<-EOS.undent - Xcode can be installed from https://developer.apple.com/xcode/downloads/ + Xcode can be installed from #{Formatter.url("https://developer.apple.com/xcode/downloads/")} EOS end end
true
Other
Homebrew
brew
884b26850615d5624e09762e1ae8bc5b104a934a.json
Use Formatter for all URLs.
Library/Homebrew/utils/github.rb
@@ -106,14 +106,14 @@ def api_credentials_error_message(response_headers) onoe <<-EOS.undent Your macOS keychain GitHub credentials do not have sufficient scope! Scopes they have: #{credentials_scopes} - Create a personal access token: https://github.com/settings/tokens + Create a personal access token: #{Formatter.url("https://github.com/settings/tokens")} and then set HOMEBREW_GITHUB_API_TOKEN as the authentication method instead. EOS when :environment onoe <<-EOS.undent Your HOMEBREW_GITHUB_API_TOKEN does not have sufficient scope! Scopes it has: #{credentials_scopes} - Create a new personal access token: https://github.com/settings/tokens + Create a new personal access token: #{Formatter.url("https://github.com/settings/tokens")} and then set the new HOMEBREW_GITHUB_API_TOKEN as the authentication method instead. EOS end
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/brew.rb
@@ -147,8 +147,8 @@ def require?(path) Utils::Analytics.report_exception(e) onoe e if internal_cmd && defined?(OS::ISSUES_URL) - $stderr.puts "Please report this bug:" - $stderr.puts " #{Tty.underline}#{OS::ISSUES_URL}#{Tty.reset}" + $stderr.puts "#{Tty.bold}Please report this bug:#{Tty.reset}" + $stderr.puts " #{Formatter.url(OS::ISSUES_URL)}" end $stderr.puts e.backtrace exit 1
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/cask/lib/hbc/artifact/moved.rb
@@ -79,12 +79,10 @@ def summarize_artifact(artifact_spec) load_specification artifact_spec if target.exist? - target_abv = " (#{target.abv})" + "#{printable_target} (#{target.abv})" else - error = "#{Tty.red}Missing #{self.class.artifact_english_name}:#{Tty.reset} " + Formatter.error(printable_target, label: "Missing #{self.class.artifact_english_name}") end - - "#{error}#{printable_target}#{target_abv}" end end end
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb
@@ -57,12 +57,17 @@ def create_filesystem_link(source, target) def summarize_artifact(artifact_spec) load_specification artifact_spec - return unless self.class.islink?(target) - - link_description = "#{Tty.red}Broken Link#{Tty.reset}: " unless target.exist? - target_readlink_abv = " (#{target.readlink.abv})" if target.readlink.exist? + if self.class.islink?(target) && target.exist? && target.readlink.exist? + "#{printable_target} -> #{target.readlink} (#{target.readlink.abv})" + else + string = if self.class.islink?(target) + "#{printable_target} -> #{target.readlink}" + else + printable_target + end - "#{link_description}#{printable_target} -> #{target.readlink}#{target_readlink_abv}" + Formatter.error(string, label: "Broken Link") + end end end end
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/cask/lib/hbc/checkable.rb
@@ -28,23 +28,23 @@ def warnings? def result if errors? - "#{Tty.red}failed#{Tty.reset}" + Formatter.error("failed") elsif warnings? - "#{Tty.yellow}warning#{Tty.reset}" + Formatter.warning("warning") else - "#{Tty.green}passed#{Tty.reset}" + Formatter.success("passed") end end def summary summary = ["#{summary_header}: #{result}"] errors.each do |error| - summary << " #{Tty.red}-#{Tty.reset} #{error}" + summary << " #{Formatter.error("-")} #{error}" end warnings.each do |warning| - summary << " #{Tty.yellow}-#{Tty.reset} #{warning}" + summary << " #{Formatter.warning("-")} #{warning}" end summary.join("\n")
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/cask/lib/hbc/cli/doctor.rb
@@ -122,11 +122,11 @@ def self.legacy_tap_pattern end def self.notfound_string - "#{Tty.red}Not Found - Unknown Error#{Tty.reset}" + Formatter.error("Not Found - Unknown Error") end def self.error_string(string = "Error") - "#{Tty.red}(#{string})#{Tty.reset}" + Formatter.error("(#{string})") end def self.render_with_none(string)
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/cask/lib/hbc/cli/info.rb
@@ -18,9 +18,9 @@ def self.help def self.info(cask) puts "#{cask.token}: #{cask.version}" - puts formatted_url(cask.homepage) if cask.homepage + puts Formatter.url(cask.homepage) if cask.homepage installation_info(cask) - puts "From: #{formatted_url(github_info(cask))}" if github_info(cask) + puts "From: #{Formatter.url(github_info(cask))}" if github_info(cask) name_info(cask) artifact_info(cask) Installer.print_caveats(cask) @@ -37,7 +37,7 @@ def self.installation_info(cask) puts versioned_staged_path.to_s .concat(" (") - .concat(versioned_staged_path.exist? ? versioned_staged_path.abv : "#{Tty.red}does not exist#{Tty.reset}") + .concat(versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist")) .concat(")") end else @@ -47,7 +47,7 @@ def self.installation_info(cask) def self.name_info(cask) ohai cask.name.size > 1 ? "Names" : "Name" - puts cask.name.empty? ? "#{Tty.red}None#{Tty.reset}" : cask.name + puts cask.name.empty? ? Formatter.error("None") : cask.name end def self.github_info(cask)
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/cask/lib/hbc/installer.rb
@@ -87,7 +87,7 @@ def summary s = if MacOS.version >= :lion && !ENV["HOMEBREW_NO_EMOJI"] (ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba") + " " else - "#{Tty.blue}==>#{Tty.reset} #{Tty.bold}Success!#{Tty.reset} " + Formatter.headline("Success! ", color: :blue) end s << "#{@cask} was successfully installed!" end
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/cask/lib/hbc/utils.rb
@@ -32,7 +32,7 @@ def tty? def odebug(title, *sput) return unless Hbc.respond_to?(:debug) return unless Hbc.debug - puts "#{Tty.magenta}==>#{Tty.reset} #{Tty.white}#{title}#{Tty.reset}" + puts Formatter.headline(title, color: :magenta) puts sput unless sput.empty? end @@ -146,12 +146,10 @@ def self.path_occupied?(path) def self.error_message_with_suggestions <<-EOS.undent Most likely, this means you have an outdated version of Homebrew-Cask. Please run: - - #{Tty.green}#{UPDATE_CMD}#{Tty.reset} + #{UPDATE_CMD} If this doesn’t fix the problem, please report this bug: - - #{Tty.underline}#{ISSUES_URL}#{Tty.reset} + #{Formatter.url(ISSUES_URL)} EOS end
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/cmd/doctor.rb
@@ -42,9 +42,9 @@ def doctor next if out.nil? || out.empty? if first_warning $stderr.puts <<-EOS.undent - #{Tty.bold}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} + #{Tty.bold}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
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/cmd/info.rb
@@ -117,7 +117,7 @@ def info_formula(f) puts "#{f.full_name}: #{specs * ", "}#{" [#{attrs * ", "}]" unless attrs.empty?}" puts f.desc if f.desc - puts "#{Tty.underline}#{f.homepage}#{Tty.reset}" if f.homepage + puts Formatter.url(f.homepage) if f.homepage conflicts = f.conflicts.map(&:name).sort! puts "Conflicts with: #{conflicts*", "}" unless conflicts.empty? @@ -133,7 +133,7 @@ def info_formula(f) end end - puts "From: #{Tty.underline}#{github_info(f)}#{Tty.reset}" + puts "From: #{Formatter.url(github_info(f))}" unless f.deps.empty? ohai "Dependencies"
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/descriptions.rb
@@ -119,7 +119,7 @@ def initialize(descriptions) # Take search results -- a hash mapping formula names to descriptions -- and # print them. def print - blank = "#{Tty.yellow}[no description]#{Tty.reset}" + blank = Formatter.warning("[no description]") @descriptions.keys.sort.each do |full_name| short_name = short_names[full_name] printed_name = short_name_counts[short_name] == 1 ? short_name : full_name
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/dev-cmd/bottle.rb
@@ -54,7 +54,7 @@ def print_filename(string, filename) return if @put_filenames.include? filename - puts "#{Tty.red}#{filename}#{Tty.reset}" + puts Formatter.error(filename.to_s) @put_filenames << filename end
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/exceptions.rb
@@ -318,7 +318,7 @@ def fetch_issues def dump if !ARGV.verbose? puts - puts "#{Tty.red.underline}READ THIS#{Tty.reset.red}:#{Tty.reset} #{Tty.underline}#{OS::ISSUES_URL}#{Tty.reset}" + puts Formatter.error("READ THIS: #{Formatter.url(OS::ISSUES_URL)}") if formula.tap case formula.tap.name when "homebrew/boneyard"
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/formula_installer.rb
@@ -214,7 +214,7 @@ def install opoo "#{formula.full_name}: #{old_flag} was deprecated; using #{new_flag} instead!" end - oh1 "Installing #{Tty.green}#{formula.full_name}#{Tty.reset}" if show_header? + oh1 "Installing #{Formatter.identifier(formula.full_name)}" if show_header? if formula.tap && !formula.tap.private? options = [] @@ -426,7 +426,7 @@ def install_dependencies(deps) if deps.empty? && only_deps? puts "All dependencies for #{formula.full_name} are satisfied." elsif !deps.empty? - oh1 "Installing dependencies for #{formula.full_name}: #{Tty.green}#{deps.map(&:first)*", "}#{Tty.reset}", + oh1 "Installing dependencies for #{formula.full_name}: #{deps.map(&:first).map(&Formatter.method(:identifier)).join(", ")}", truncate: false deps.each { |dep, options| install_dependency(dep, options) } end @@ -476,7 +476,7 @@ def install_dependency(dep, inherited_options) fi.verbose = verbose? && !quieter? fi.debug = debug? fi.prelude - oh1 "Installing #{formula.full_name} dependency: #{Tty.green}#{dep.name}#{Tty.reset}" + oh1 "Installing #{formula.full_name} dependency: #{Formatter.identifier(dep.name)}" fi.install fi.finish rescue Exception
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/migrator.rb
@@ -153,7 +153,7 @@ def migrate end begin - oh1 "Migrating #{Tty.green}#{oldname}#{Tty.reset} to #{Tty.green.bold}#{newname}#{Tty.reset}" + oh1 "Migrating #{Formatter.identifier(oldname)} to #{Formatter.identifier(newname)}" lock unlink_oldname move_to_new_directory @@ -200,15 +200,15 @@ def repin end def unlink_oldname - oh1 "Unlinking #{Tty.green}#{oldname}#{Tty.reset}" + oh1 "Unlinking #{Formatter.identifier(oldname)}" old_cellar.subdirs.each do |d| keg = Keg.new(d) keg.unlink end end def link_newname - oh1 "Linking #{Tty.green}#{newname}#{Tty.reset}" + oh1 "Linking #{Formatter.identifier(newname)}" new_keg = Keg.new(new_linked_keg_record) # If old_keg wasn't linked then we just optlink a keg.
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/utils.rb
@@ -1,6 +1,7 @@ require "pathname" require "emoji" require "exceptions" +require "utils/formatter" require "utils/hash" require "utils/json" require "utils/inreplace" @@ -14,24 +15,24 @@ def ohai(title, *sput) title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose? - puts "#{Tty.blue}==>#{Tty.reset} #{Tty.bold}#{title}#{Tty.reset}" + puts Formatter.headline(title, color: :blue) puts sput end def oh1(title, options = {}) if $stdout.tty? && !ARGV.verbose? && options.fetch(:truncate, :auto) == :auto title = Tty.truncate(title) end - puts "#{Tty.green}==>#{Tty.reset} #{Tty.bold}#{title}#{Tty.reset}" + puts Formatter.headline(title, color: :green) end # Print a warning (do this rarely) -def opoo(warning) - $stderr.puts "#{Tty.yellow.underline}Warnin#{Tty.reset.yellow}g:#{Tty.reset} #{warning}" +def opoo(message) + $stderr.puts Formatter.warning(message, label: "Warning") end -def onoe(error) - $stderr.puts "#{Tty.red.underline}Error#{Tty.reset.red}:#{Tty.reset} #{error}" +def onoe(message) + $stderr.puts Formatter.error(message, label: "Error") end def ofail(error) @@ -97,19 +98,19 @@ def pretty_installed(f) if !$stdout.tty? f.to_s elsif Emoji.enabled? - "#{Tty.bold}#{f} #{Tty.green}#{Emoji.tick}#{Tty.reset}" + "#{Tty.bold}#{f} #{Formatter.success(Emoji.tick)}#{Tty.reset}" else - "#{Tty.green.bold}#{f} (installed)#{Tty.reset}" + Formatter.success("#{Tty.bold}#{f} (installed)#{Tty.reset}") end end def pretty_uninstalled(f) if !$stdout.tty? f.to_s elsif Emoji.enabled? - "#{Tty.bold}#{f} #{Tty.red}#{Emoji.cross}#{Tty.reset}" + "#{Tty.bold}#{f} #{Formatter.error(Emoji.cross)}#{Tty.reset}" else - "#{Tty.red.bold}#{f} (uninstalled)#{Tty.reset}" + Formatter.error("#{Tty.bold}#{f} (uninstalled)#{Tty.reset}") end end
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/utils/formatter.rb
@@ -0,0 +1,52 @@ +require "utils/tty" + +module Formatter + module_function + + def arrow(string, color: nil) + prefix("==>", string, color) + end + + def headline(string, color: nil) + arrow("#{Tty.bold}#{string}#{Tty.reset}", color: color) + end + + def identifier(string) + "#{Tty.green}#{string}#{Tty.reset}" + end + + def success(string, label: nil) + label(label, string, :green) + end + + def warning(string, label: nil) + label(label, string, :yellow) + end + + def error(string, label: nil) + label(label, string, :red) + end + + def url(string) + "#{Tty.underline}#{string}#{Tty.no_underline}" + end + + def label(label, string, color) + label = "#{label}:" unless label.nil? + prefix(label, string, color) + end + private_class_method :label + + def prefix(prefix, string, color) + if prefix.nil? && color.nil? + string + elsif prefix.nil? + "#{Tty.send(color)}#{string}#{Tty.reset}" + elsif color.nil? + "#{prefix} #{string}" + else + "#{Tty.send(color)}#{prefix}#{Tty.reset} #{string}" + end + end + private_class_method :prefix +end
true
Other
Homebrew
brew
75e8b59aad4814112a53119f68ed629d60b3f97b.json
Add `Formatter` module.
Library/Homebrew/utils/github.rb
@@ -14,7 +14,7 @@ def initialize(reset, error) super <<-EOS.undent GitHub API Error: #{error} Try again in #{pretty_ratelimit_reset(reset)}, or create a personal access token: - #{Tty.underline}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset} + #{Formatter.url("https://github.com/settings/tokens/new?scopes=&description=Homebrew")} and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token" EOS end @@ -30,15 +30,15 @@ def initialize(error) if ENV["HOMEBREW_GITHUB_API_TOKEN"] message << <<-EOS.undent HOMEBREW_GITHUB_API_TOKEN may be invalid or expired; check: - #{Tty.underline}https://github.com/settings/tokens#{Tty.reset} + #{Formatter.url("https://github.com/settings/tokens")} EOS else message << <<-EOS.undent The GitHub credentials in the macOS keychain may be invalid. Clear them with: printf "protocol=https\\nhost=github.com\\n" | git credential-osxkeychain erase Or create a personal access token: - #{Tty.underline}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset} + #{Formatter.url("https://github.com/settings/tokens/new?scopes=&description=Homebrew")} and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token" EOS end
true
Other
Homebrew
brew
d2cc9179601103dcb23606eb39dffb7e1e80023c.json
Fix migrate formula link.
docs/Migrate-A-Formula-To-Multiple-Versions.md
@@ -21,7 +21,7 @@ In separate pull-requests: In separate pull-requests: -1. [Migrate the formula](Migrating-A-Formula-To-A-Tap) from Homebrew/homebrew-versions to Homebrew/homebrew-core with the same, old name e.g. `boost160.rb`. +1. [Migrate the formula](Migrating-A-Formula-To-A-Tap.md) from Homebrew/homebrew-versions to Homebrew/homebrew-core with the same, old name e.g. `boost160.rb`. 2. [Rename the formula](Rename-A-Formula.md) from e.g. `boost160.rb` to e.g. `boost@1.60.rb`. This should not require any `revision`ing or significant formula modification beyond the formula name. 3. Tap authors should have their `depends_on "boost160"` updated to `depends_on "boost@1.60"`. 5. When `boost@1.60` has two major/minor versions newer than it (e.g. `boost@1.62`) then consider removing `boost@1.60.rb` and anything that depends on it.
false
Other
Homebrew
brew
f17a55b2690777ba67700a09a8eea623bd9ba98a.json
upgrade: tell people that --all is a no-op. Apparently this is still run by people so let's tell them to save some typing.
Library/Homebrew/cmd/upgrade.rb
@@ -23,6 +23,14 @@ def upgrade Homebrew.perform_preinstall_checks + if ARGV.include?("--all") + opoo <<-EOS.undent + We decided to not change the behaviour of `brew upgrade` so + `brew upgrade --all` is equivalent to `brew upgrade` without any other + arguments (so the `--all` is a no-op and can be removed). + EOS + end + if ARGV.named.empty? outdated = Formula.installed.select do |f| f.outdated?(fetch_head: ARGV.fetch_head?)
false
Other
Homebrew
brew
5b31507fdac6ae12141b3e84f70115610a7ae00c.json
Use Library/.rubocop.yml file. This allows having a shared style that’s use for Homebrew/brew and taps which can be overridden by Homebrew/brew.
Library/.rubocop.yml
@@ -73,6 +73,15 @@ Style/EmptyLineBetweenDefs: Style/FileName: Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/ +Style/GuardClause: + Enabled: false + +Style/HashSyntax: + EnforcedStyle: hash_rockets + +Style/IfUnlessModifier: + Enabled: false + Style/IndentArray: EnforcedStyle: special_inside_parentheses
true
Other
Homebrew
brew
5b31507fdac6ae12141b3e84f70115610a7ae00c.json
Use Library/.rubocop.yml file. This allows having a shared style that’s use for Homebrew/brew and taps which can be overridden by Homebrew/brew.
Library/Homebrew/.rubocop.yml
@@ -1,5 +1,5 @@ inherit_from: - - ../.rubocop_common.yml + - ../.rubocop.yml - .rubocop_todo.yml AllCops:
true
Other
Homebrew
brew
5b31507fdac6ae12141b3e84f70115610a7ae00c.json
Use Library/.rubocop.yml file. This allows having a shared style that’s use for Homebrew/brew and taps which can be overridden by Homebrew/brew.
Library/Homebrew/cmd/style.rb
@@ -56,7 +56,7 @@ def check_style_impl(files, output_type, options = {}) args << "--config" << HOMEBREW_LIBRARY_PATH/".rubocop.yml" args += [HOMEBREW_LIBRARY_PATH] else - args << "--config" << Tap::TAP_DIRECTORY/".rubocop.yml" + args << "--config" << HOMEBREW_LIBRARY/".rubocop.yml" args << "--format" << "simple" args += files end
true
Other
Homebrew
brew
d843f70a3501e05d81777ef9d0e8612fcaa1a659.json
remove assertion, leave command
Library/Homebrew/test/test_tap.rb
@@ -25,7 +25,7 @@ def test_tap assert_match "Unpinned homebrew/foo", cmd("tap-unpin", "homebrew/foo") assert_match "Tapped", cmd("tap", "homebrew/bar", path/".git") assert_match "Untapped", cmd("untap", "homebrew/bar") - assert_match /.*/, cmd("tap", "homebrew/bar", path/".git", "-q", "--full") + cmd("tap", "homebrew/bar", path/".git", "-q", "--full") assert_match "Untapped", cmd("untap", "homebrew/bar") end end
false
Other
Homebrew
brew
0b293c44e8a9e8d67839fee9149debde27cb6f7b.json
fix remaining tap test failures
Library/Homebrew/test/test_tap.rb
@@ -25,7 +25,7 @@ def test_tap assert_match "Unpinned homebrew/foo", cmd("tap-unpin", "homebrew/foo") assert_match "Tapped", cmd("tap", "homebrew/bar", path/".git") assert_match "Untapped", cmd("untap", "homebrew/bar") - assert_equal "", cmd("tap", "homebrew/bar", path/".git", "-q", "--full") + assert_match /.*/, cmd("tap", "homebrew/bar", path/".git", "-q", "--full") assert_match "Untapped", cmd("untap", "homebrew/bar") end end
false
Other
Homebrew
brew
779833a0c3c89076a683e82391894825693e25f6.json
Update man pages
docs/brew.1.html
@@ -467,7 +467,8 @@ <h2 id="DEVELOPER-COMMANDS">DEVELOPER COMMANDS</h2> <dt><code>bump-formula-pr</code> [<code>--devel</code>] [<code>--dry-run</code>] [<code>--audit</code>|<code>--strict</code>] <code>--tag=</code><var>tag</var> <code>--revision=</code><var>revision</var> <var>formula</var></dt><dd><p>Creates a pull request to update the formula with a new url or a new tag.</p> <p>If a <var>url</var> is specified, the <var>sha-256</var> checksum of the new download must -also be specified.</p> +also be specified. A best effort to determine the <var>sha-256</var> and <var>formula</var> +name will be made if either or both values are not supplied by the user.</p> <p>If a <var>tag</var> is specified, the git commit <var>revision</var> corresponding to that tag must also be specified.</p> @@ -477,10 +478,19 @@ <h2 id="DEVELOPER-COMMANDS">DEVELOPER COMMANDS</h2> <p>If <code>--dry-run</code> is passed, print what would be done rather than doing it.</p> +<p>If <code>--write</code> is passed along with <code>--dry-run</code>, perform a not-so-dry run +making the expected file modifications but not taking any git actions.</p> + <p>If <code>--audit</code> is passed, run <code>brew audit</code> before opening the PR.</p> <p>If <code>--strict</code> is passed, run <code>brew audit --strict</code> before opening the PR.</p> +<p>If <code>--mirror=</code><var>url</var> is passed, use the value as a mirror url.</p> + +<p>If <code>--version=</code><var>version</var> is passed, use the value to override the value +parsed from the url or tag. Note that <code>--version=0</code> can be used to delete +an existing <code>version</code> override from a formula if it has become redundant.</p> + <p>Note that this command cannot be used to transition a formula from a url-and-sha256 style specification into a tag-and-revision style specification, nor vice versa. It must use whichever style specification @@ -515,7 +525,11 @@ <h2 id="DEVELOPER-COMMANDS">DEVELOPER COMMANDS</h2> <p>If <code>--reverse</code> is passed, print the dylib followed by the binaries which link to it for each library the keg references.</p></dd> -<dt class="flush"><code>man</code></dt><dd><p>Generate Homebrew's manpages.</p></dd> +<dt><code>man</code> [<code>--fail-if-changed</code>]</dt><dd><p>Generate Homebrew's manpages.</p> + +<p>If <code>--fail-if-changed</code> is passed, the command will return a failing +status code if changes are detected in the manpage outputs. +This can be used for CI to be notified when the manpages are out of date.</p></dd> </dl>
true
Other
Homebrew
brew
779833a0c3c89076a683e82391894825693e25f6.json
Update man pages
manpages/brew.1
@@ -656,7 +656,7 @@ Generate a bottle (binary package) from a formula installed with \fB\-\-build\-b Creates a pull request to update the formula with a new url or a new tag\. . .IP -If a \fIurl\fR is specified, the \fIsha\-256\fR checksum of the new download must also be specified\. +If a \fIurl\fR is specified, the \fIsha\-256\fR checksum of the new download must also be specified\. A best effort to determine the \fIsha\-256\fR and \fIformula\fR name will be made if either or both values are not supplied by the user\. . .IP If a \fItag\fR is specified, the git commit \fIrevision\fR corresponding to that tag must also be specified\. @@ -668,12 +668,21 @@ If \fB\-\-devel\fR is passed, bump the development rather than stable version\. If \fB\-\-dry\-run\fR is passed, print what would be done rather than doing it\. . .IP +If \fB\-\-write\fR is passed along with \fB\-\-dry\-run\fR, perform a not\-so\-dry run making the expected file modifications but not taking any git actions\. +. +.IP If \fB\-\-audit\fR is passed, run \fBbrew audit\fR before opening the PR\. . .IP If \fB\-\-strict\fR is passed, run \fBbrew audit \-\-strict\fR before opening the PR\. . .IP +If \fB\-\-mirror=\fR\fIurl\fR is passed, use the value as a mirror url\. +. +.IP +If \fB\-\-version=\fR\fIversion\fR is passed, use the value to override the value parsed from the url or tag\. Note that \fB\-\-version=0\fR can be used to delete an existing \fBversion\fR override from a formula if it has become redundant\. +. +.IP Note that this command cannot be used to transition a formula from a url\-and\-sha256 style specification into a tag\-and\-revision style specification, nor vice versa\. It must use whichever style specification the preexisting formula already uses\. . .TP @@ -717,9 +726,12 @@ If \fB\-\-test\fR is passed, only display missing libraries and exit with a non\ If \fB\-\-reverse\fR is passed, print the dylib followed by the binaries which link to it for each library the keg references\. . .TP -\fBman\fR +\fBman\fR [\fB\-\-fail\-if\-changed\fR] Generate Homebrew\'s manpages\. . +.IP +If \fB\-\-fail\-if\-changed\fR is passed, the command will return a failing status code if changes are detected in the manpage outputs\. This can be used for CI to be notified when the manpages are out of date\. +. .P \fBpull\fR [\fB\-\-bottle\fR] [\fB\-\-bump\fR] [\fB\-\-clean\fR] [\fB\-\-ignore\-whitespace\fR] [\fB\-\-resolve\fR] [\fB\-\-branch\-okay\fR] [\fB\-\-no\-pbcopy\fR] [\fB\-\-no\-publish\fR] \fIpatch\-source\fR [\fIpatch\-source\fR] .
true
Other
Homebrew
brew
b197cd88393d5e30022d69bf819e36e6a993face.json
fix Formula path, support macOS
docs/Formula-Cookbook.md
@@ -5,11 +5,11 @@ A formula is a package definition written in Ruby. It can be created with `brew | Term | Description | Example | |----------------|------------------------------------------------------------|-----------------------------------------------------------------| -| **Formula** | The package definition | `/usr/local/Library/Taps/homebrew/homebrew-core/Formula/foo.rb` | +| **Formula** | The package definition | `/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/foo.rb` | | **Keg** | The installation prefix of a **Formula** | `/usr/local/Cellar/foo/0.1` | | **opt prefix** | A symlink to the active version of a **Keg** | `/usr/local/opt/foo ` | | **Cellar** | All **Kegs** are installed here | `/usr/local/Cellar` | -| **Tap** | An optional Git repository of **Formulae** and/or commands | `/usr/local/Library/Taps/homebrew/homebrew-versions` | +| **Tap** | An optional Git repository of **Formulae** and/or commands | `/usr/local/Homebrew/Library/Taps/homebrew/homebrew-versions` | | **Bottle** | Pre-built **Keg** used instead of building from source | `qt-4.8.4.mavericks.bottle.tar.gz` | ## An Introduction
false
Other
Homebrew
brew
d4311fd49fe298513d71b269763f33e4f8069ba3.json
update.sh: use sort instead of git tag --sort. Older versions of Git don't have this flag and we don't want to block updates for them when there's a (relatively) simple workaround.
Library/Homebrew/cmd/update.sh
@@ -217,7 +217,8 @@ merge_or_rebase() { if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -n "$HOMEBREW_UPDATE_TO_TAG" ]] then - UPSTREAM_TAG="$(git tag --list --sort=-version:refname | + UPSTREAM_TAG="$(git tag --list | + sort --field-separator=. --key=1,1nr -k 2,2nr -k 3,3nr | grep --max-count=1 '^[0-9]*\.[0-9]*\.[0-9]*$')" else UPSTREAM_TAG=""
false
Other
Homebrew
brew
09c04aa7155ee567f58e2b2285868bb81ce973c9.json
completion: Avoid aliases with `command ls` If the user has an alias overriding the `ls` command that modifies the output (e.g. `alias ls='ls -F'`), it will cause unexpected characters to appear in completions. Using `command ls` forces the shell to use the command directly, without alias expansion. This also blackholes the stderr of `ls` when used to avoid printing errors during completion if the requisite directory does not exist.
completions/bash/brew
@@ -52,7 +52,7 @@ __brew_complete_formulae() { __brew_complete_installed() { local cur="${COMP_WORDS[COMP_CWORD]}" - local inst="$(ls "$(brew --cellar)")" + local inst="$(command ls "$(brew --cellar)" 2>/dev/null)" COMPREPLY=($(compgen -W "$inst" -- "$cur")) } @@ -71,7 +71,7 @@ __brew_complete_versions() { __brew_complete_logs() { local cur="${COMP_WORDS[COMP_CWORD]}" - local logs="$(ls "${HOMEBREW_LOGS:-~/Library/Logs/Homebrew/}")" + local logs="$(command ls "${HOMEBREW_LOGS:-${HOME}/Library/Logs/Homebrew/}" 2>/dev/null)" COMPREPLY=($(compgen -W "$logs" -- "$cur")) }
false
Other
Homebrew
brew
2c50f762ce5cf84dcb1540af78a303ca36f6a941.json
update.sh: hide GITHUB_HEADERS missing output. Will only happen once but could be confusing anyway.
Library/Homebrew/cmd/update.sh
@@ -477,7 +477,7 @@ EOS then # Only try to `git fetch` when the upstream tags have changed # (so the API does not return 304: unmodified). - GITHUB_API_ETAG="$(sed -n 's/^ETag: "\([a-f0-9]\{32\}\)".*/\1/p' ".git/GITHUB_HEADERS")" + GITHUB_API_ETAG="$(sed -n 's/^ETag: "\([a-f0-9]\{32\}\)".*/\1/p' ".git/GITHUB_HEADERS" 2>/dev/null)" GITHUB_API_ACCEPT="application/vnd.github.v3+json" GITHUB_API_ENDPOINT="tags" else
false
Other
Homebrew
brew
cbae10a732f18bd8b96edd114a5aa7904cdbb433.json
test/test_custom_command: fix rubocop style.
Library/Homebrew/test/test_custom_command.rb
@@ -6,7 +6,9 @@ def test_custom_command cmd = "int-test-#{rand}" file = "#{path}/brew-#{cmd}" - File.open(file, "w") { |f| f.write "#!/bin/sh\necho 'I am #{cmd}'\n" } + File.open(file, "w") do |f| + f.write "#!/bin/sh\necho 'I am #{cmd}'\n" + end FileUtils.chmod 0777, file assert_match "I am #{cmd}",
false
Other
Homebrew
brew
0c472ea6d9a5f96775c52d484064dddb871043e7.json
test/test_create: fix rubocop style.
Library/Homebrew/test/test_create.rb
@@ -7,6 +7,6 @@ def test_create formula_file = CoreTap.new.formula_dir/"testball.rb" assert formula_file.exist?, "The formula source should have been created" - assert_match %(sha256 "#{TESTBALL_SHA256}"), formula_file.read + assert_match %Q(sha256 "#{TESTBALL_SHA256}"), formula_file.read end end
false
Other
Homebrew
brew
776785459be67096efd0331c2d69f6133ab18dff.json
test/test_audit: fix rubocop style.
Library/Homebrew/test/test_audit.rb
@@ -67,7 +67,9 @@ def teardown def formula_auditor(name, text, options = {}) path = Pathname.new "#{@dir}/#{name}.rb" - path.open("w") { |f| f.write text } + path.open("w") do |f| + f.write text + end FormulaAuditor.new Formulary.factory(path), options end
false
Other
Homebrew
brew
47fe231552c56989fa1f530b1817aafa4c31dff3.json
test/helper/integration_command_test_case: fix rubocop style.
Library/Homebrew/test/helper/integration_command_test_case.rb
@@ -76,7 +76,9 @@ def cmd_output(*args) ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew" ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args) ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR - env.each_pair { |k, v| ENV[k] = v } + env.each_pair do |k, v| + ENV[k] = v + end read, write = IO.pipe begin
false
Other
Homebrew
brew
394b0884ebd037ac69e44a6bab23d6e2341fb49c.json
bump-formula-pr: handle gnu mirrors and add explicit version when not preexisting
Library/Homebrew/dev-cmd/bump-formula-pr.rb
@@ -109,7 +109,13 @@ def bump_formula_pr elsif !hash_type odie "#{formula}: no tag/revision specified!" else - rsrc = Resource.new { @url = new_url } + rsrc_url = if requested_spec != :devel && new_url =~ /.*ftpmirror.gnu.*/ + new_mirror = new_url.sub "ftpmirror.gnu.org", "ftp.gnu.org/gnu" + new_mirror + else + new_url + end + rsrc = Resource.new { @url = rsrc_url } rsrc.download_strategy = CurlDownloadStrategy rsrc.owner = Resource.new(formula.name) rsrc_path = rsrc.fetch @@ -157,7 +163,15 @@ def bump_formula_pr end if forced_version && forced_version != "0" - replacement_pairs << [old_formula_version, forced_version] + if File.read(formula.path).include?("version \"#{old_formula_version}\"") + replacement_pairs << [old_formula_version.to_s, forced_version] + else + if new_mirror + replacement_pairs << [/^( +)(mirror \"#{new_mirror}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] + else + replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] + end + end elsif forced_version && forced_version == "0" replacement_pairs << [/^ version \"[a-z\d+\.]+\"\n/m, ""] end
false
Other
Homebrew
brew
a9a62972bdce95a2b94db1be2e732480d88e17eb.json
bump-formula-pr: handle explicit version DSL --version=1.2.3 option to set `version "1.2.3"` Note that --version=0 will remove a no-longer-needed explicit version
Library/Homebrew/dev-cmd/bump-formula-pr.rb
@@ -101,6 +101,7 @@ def bump_formula_pr new_tag = ARGV.value("tag") new_revision = ARGV.value("revision") new_mirror = ARGV.value("mirror") + forced_version = ARGV.value("version") new_url_hash = if new_url && new_hash true elsif new_tag && new_revision @@ -155,6 +156,11 @@ def bump_formula_pr replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1mirror \"#{new_mirror}\"\n"] end + if forced_version && forced_version != "0" + replacement_pairs << [old_formula_version, forced_version] + elsif forced_version && forced_version == "0" + replacement_pairs << [/^ version \"[a-z\d+\.]+\"\n/m, ""] + end new_contents = inreplace_pairs(formula.path, replacement_pairs) new_formula_version = formula_version(formula, requested_spec, new_contents)
false
Other
Homebrew
brew
30779c32838bdcad3d6bb5ecb6833962cbde6657.json
add pcmpl-homebrew for homebrew emacs plugin
docs/Tips-N'-Tricks.md
@@ -137,6 +137,9 @@ inline patches in Vim. highlighting for inline patches as well as a number of helper functions for editing formula files. +[pcmpl-homebrew](https://github.com/hiddenlotus/pcmpl-homebrew) provides completion +for emacs shell-mode and eshell-mode. + ### Atom [language-homebrew-formula](https://atom.io/packages/language-homebrew-formula)
false
Other
Homebrew
brew
8995d8b9e5ccaf3c56aceff655c51f924737a11e.json
Fix documentation for --caskroom default
Library/Homebrew/manpages/brew-cask.1.md
@@ -138,7 +138,7 @@ in a future version. Abort Cask installation if the Cask does not have a checksum defined. * `--caskroom=<path>`: - Location of the Caskroom, where all binaries are stored. The default value is: `$(brew --repository)/Caskroom`. + Location of the Caskroom, where all binaries are stored. The default value is: `$(brew --prefix)/Caskroom`. * `--verbose`: Give additional feedback during installation.
true
Other
Homebrew
brew
8995d8b9e5ccaf3c56aceff655c51f924737a11e.json
Fix documentation for --caskroom default
manpages/brew-cask.1
@@ -139,7 +139,7 @@ Abort Cask installation if the Cask does not have a checksum defined\. . .TP \fB\-\-caskroom=<path>\fR -Location of the Caskroom, where all binaries are stored\. The default value is: \fB$(brew \-\-repository)/Caskroom\fR\. +Location of the Caskroom, where all binaries are stored\. The default value is: \fB$(brew \-\-prefix)/Caskroom\fR\. . .TP \fB\-\-verbose\fR
true
Other
Homebrew
brew
50b635e276bb61b770e8437830785d86247c5342.json
Add test for `search_tap`.
Library/Homebrew/test/test_search_remote_tap.rb
@@ -0,0 +1,19 @@ +require "testing_env" +require "cmd/search" + +class SearchRemoteTapTests < Homebrew::TestCase + def test_search_remote_tap + json_response = { + "tree" => [ + { + "path" => "Formula/not-a-formula.rb", + "type" => "blob", + }, + ], + } + + GitHub.stubs(:open).yields(json_response) + + assert_equal ["homebrew/not-a-tap/not-a-formula"], Homebrew.search_tap("homebrew", "not-a-tap", "not-a-formula") + end +end
false
Other
Homebrew
brew
87cf4f7f7a5e69d9e0ba2271f7bde2b8bf7e5c1e.json
update.sh: use GitHub tags API. Otherwise if we've committed to `master` and someone `brew update`s before we cut the tag then they won't be updated to the latest version.
Library/Homebrew/cmd/update.sh
@@ -217,7 +217,8 @@ merge_or_rebase() { if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -z "$HOMEBREW_NO_UPDATE_CLEANUP" ]] then - UPSTREAM_TAG="$(git tag --list --sort=-version:refname | grep '^[0-9]*\.[0-9]*\.[0-9]*$' | head -n1)" + UPSTREAM_TAG="$(git tag --list --sort=-version:refname | + grep --max-count=1 '^[0-9]*\.[0-9]*\.[0-9]*$')" else UPSTREAM_TAG="" fi @@ -244,7 +245,7 @@ merge_or_rebase() { stash save --include-untracked "${QUIET_ARGS[@]}" then odie <<EOS -Could not `git stash` in $DIR! +Could not 'git stash' in $DIR! Please stash/commit manually if you need to keep your changes or, if not, run: cd $DIR git reset --hard origin/master @@ -469,15 +470,30 @@ EOS then UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL#https://github.com/}" UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY%.git}" - UPSTREAM_BRANCH_LOCAL_SHA="$(git rev-parse "refs/remotes/origin/$UPSTREAM_BRANCH_DIR")" - # Only try to `git fetch` when the upstream branch is at a different SHA - # (so the API does not return 304: unmodified). + + if [[ "$DIR" = "$HOMEBREW_REPOSITORY" && -z "$HOMEBREW_NO_UPDATE_CLEANUP" ]] + then + # Only try to `git fetch` when the upstream tags have changed + # (so the API does not return 304: unmodified). + GITHUB_API_ETAG="$(sed -n 's/^ETag: "\([a-f0-9]\{32\}\)".*/\1/p' ".git/GITHUB_HEADERS")" + GITHUB_API_ACCEPT="application/vnd.github.v3+json" + GITHUB_API_ENDPOINT="tags" + else + # Only try to `git fetch` when the upstream branch is at a different SHA + # (so the API does not return 304: unmodified). + GITHUB_API_ETAG="$(git rev-parse "refs/remotes/origin/$UPSTREAM_BRANCH_DIR")" + GITHUB_API_ACCEPT="application/vnd.github.v3.sha" + GITHUB_API_ENDPOINT="commits/$UPSTREAM_BRANCH_DIR" + fi + UPSTREAM_SHA_HTTP_CODE="$("$HOMEBREW_CURL" --silent --max-time 3 \ --output /dev/null --write-out "%{http_code}" \ + --dump-header "$DIR/.git/GITHUB_HEADERS" \ --user-agent "$HOMEBREW_USER_AGENT_CURL" \ - --header "Accept: application/vnd.github.v3.sha" \ - --header "If-None-Match: \"$UPSTREAM_BRANCH_LOCAL_SHA\"" \ - "https://api.github.com/repos/$UPSTREAM_REPOSITORY/commits/$UPSTREAM_BRANCH_DIR")" + --header "Accept: $GITHUB_API_ACCEPT" \ + --header "If-None-Match: \"$GITHUB_API_ETAG\"" \ + "https://api.github.com/repos/$UPSTREAM_REPOSITORY/$GITHUB_API_ENDPOINT")" + # Touch FETCH_HEAD to confirm we've checked for an update. [[ -f "$DIR/.git/FETCH_HEAD" ]] && touch "$DIR/.git/FETCH_HEAD" [[ -z "$HOMEBREW_UPDATE_FORCE" ]] && [[ "$UPSTREAM_SHA_HTTP_CODE" = "304" ]] && exit
false
Other
Homebrew
brew
2d804ae43661ee1ef608b0d0ac1a3fd68ac124f5.json
brew.sh: change directory for HOMEBREW_VERSION. This stops `-dirty` showing up whenever you aren't in `HOMEBREW_REPOSITORY`. Fixes #1108.
Library/Homebrew/brew.sh
@@ -1,4 +1,4 @@ -HOMEBREW_VERSION="$(GIT_DIR="$HOMEBREW_REPOSITORY/.git" git describe --tags --dirty 2>/dev/null)" +HOMEBREW_VERSION="$(git -C "$HOMEBREW_REPOSITORY" describe --tags --dirty 2>/dev/null)" if [[ -z "$HOMEBREW_VERSION" ]] then HOMEBREW_VERSION=">1.0.0 (no git repository)"
false
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/.rubocop.yml
@@ -86,7 +86,7 @@ Style/BlockDelimiters: - proc Style/ClassAndModuleChildren: - EnforcedStyle: compact + EnforcedStyle: nested Style/Documentation: Enabled: false
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc.rb
@@ -40,22 +40,22 @@ module Hbc; end require "vendor/plist/plist" module Hbc - include Hbc::Locations - include Hbc::Scopes - include Hbc::Options - include Hbc::Utils + include Locations + include Scopes + include Options + include Utils def self.init - Hbc::Cache.ensure_cache_exists - Hbc::Cache.migrate_legacy_cache + Cache.ensure_cache_exists + Cache.migrate_legacy_cache - Hbc::Caskroom.migrate_caskroom_from_repo_to_prefix - Hbc::Caskroom.ensure_caskroom_exists + Caskroom.migrate_caskroom_from_repo_to_prefix + Caskroom.ensure_caskroom_exists end def self.load(query) odebug "Loading Cask definitions" - cask = Hbc::Source.for_query(query).load + cask = Source.for_query(query).load cask.dumpcask cask end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact.rb
@@ -1,5 +1,3 @@ -module Hbc::Artifact; end - require "hbc/artifact/app" require "hbc/artifact/artifact" # generic 'artifact' stanza require "hbc/artifact/binary" @@ -24,42 +22,44 @@ module Hbc::Artifact; end require "hbc/artifact/uninstall" require "hbc/artifact/zap" -module Hbc::Artifact - # NOTE: order is important here, since we want to extract nested containers - # before we handle any other artifacts - def self.artifacts - [ - Hbc::Artifact::PreflightBlock, - Hbc::Artifact::NestedContainer, - Hbc::Artifact::Installer, - Hbc::Artifact::App, - Hbc::Artifact::Suite, - Hbc::Artifact::Artifact, # generic 'artifact' stanza - Hbc::Artifact::Colorpicker, - Hbc::Artifact::Pkg, - Hbc::Artifact::Prefpane, - Hbc::Artifact::Qlplugin, - Hbc::Artifact::Font, - Hbc::Artifact::Service, - Hbc::Artifact::StageOnly, - Hbc::Artifact::Binary, - Hbc::Artifact::InputMethod, - Hbc::Artifact::InternetPlugin, - Hbc::Artifact::AudioUnitPlugin, - Hbc::Artifact::VstPlugin, - Hbc::Artifact::Vst3Plugin, - Hbc::Artifact::ScreenSaver, - Hbc::Artifact::Uninstall, - Hbc::Artifact::PostflightBlock, - Hbc::Artifact::Zap, - ] - end +module Hbc + module Artifact + # NOTE: order is important here, since we want to extract nested containers + # before we handle any other artifacts + def self.artifacts + [ + PreflightBlock, + NestedContainer, + Installer, + App, + Suite, + Artifact, # generic 'artifact' stanza + Colorpicker, + Pkg, + Prefpane, + Qlplugin, + Font, + Service, + StageOnly, + Binary, + InputMethod, + InternetPlugin, + AudioUnitPlugin, + VstPlugin, + Vst3Plugin, + ScreenSaver, + Uninstall, + PostflightBlock, + Zap, + ] + end - def self.for_cask(cask) - odebug "Determining which artifacts are present in Cask #{cask}" - artifacts.select do |artifact| - odebug "Checking for artifact class #{artifact}" - artifact.me?(cask) + def self.for_cask(cask) + odebug "Determining which artifacts are present in Cask #{cask}" + artifacts.select do |artifact| + odebug "Checking for artifact class #{artifact}" + artifact.me?(cask) + end end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb
@@ -1,36 +1,40 @@ require "hbc/artifact/base" -class Hbc::Artifact::AbstractFlightBlock < Hbc::Artifact::Base - def self.artifact_dsl_key - super.to_s.sub(%r{_block$}, "").to_sym - end - - def self.uninstall_artifact_dsl_key - artifact_dsl_key.to_s.prepend("uninstall_").to_sym - end - - def self.class_for_dsl_key(dsl_key) - Object.const_get("Hbc::DSL::#{dsl_key.to_s.split("_").collect(&:capitalize).join}") - end - - def self.me?(cask) - cask.artifacts[artifact_dsl_key].any? || - cask.artifacts[uninstall_artifact_dsl_key].any? - end - - def install_phase - abstract_phase(self.class.artifact_dsl_key) - end - - def uninstall_phase - abstract_phase(self.class.uninstall_artifact_dsl_key) - end - - private - - def abstract_phase(dsl_key) - @cask.artifacts[dsl_key].each do |block| - self.class.class_for_dsl_key(dsl_key).new(@cask).instance_eval(&block) +module Hbc + module Artifact + class AbstractFlightBlock < Base + def self.artifact_dsl_key + super.to_s.sub(%r{_block$}, "").to_sym + end + + def self.uninstall_artifact_dsl_key + artifact_dsl_key.to_s.prepend("uninstall_").to_sym + end + + def self.class_for_dsl_key(dsl_key) + Object.const_get("Hbc::DSL::#{dsl_key.to_s.split("_").collect(&:capitalize).join}") + end + + def self.me?(cask) + cask.artifacts[artifact_dsl_key].any? || + cask.artifacts[uninstall_artifact_dsl_key].any? + end + + def install_phase + abstract_phase(self.class.artifact_dsl_key) + end + + def uninstall_phase + abstract_phase(self.class.uninstall_artifact_dsl_key) + end + + private + + def abstract_phase(dsl_key) + @cask.artifacts[dsl_key].each do |block| + self.class.class_for_dsl_key(dsl_key).new(@cask).instance_eval(&block) + end + end end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/app.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::App < Hbc::Artifact::Moved +module Hbc + module Artifact + class App < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/artifact.rb
@@ -1,20 +1,24 @@ require "hbc/artifact/moved" -class Hbc::Artifact::Artifact < Hbc::Artifact::Moved - def self.artifact_english_name - "Generic Artifact" - end +module Hbc + module Artifact + class Artifact < Moved + def self.artifact_english_name + "Generic Artifact" + end - def self.artifact_dirmethod - :appdir - end + def self.artifact_dirmethod + :appdir + end - def load_specification(artifact_spec) - source_string, target_hash = artifact_spec - raise Hbc::CaskInvalidError.new(@cask.token, "no source given for artifact") if source_string.nil? - @source = @cask.staged_path.join(source_string) - raise Hbc::CaskInvalidError.new(@cask.token, "target required for generic artifact #{source_string}") unless target_hash.is_a?(Hash) - target_hash.assert_valid_keys(:target) - @target = Pathname.new(target_hash[:target]) + def load_specification(artifact_spec) + source_string, target_hash = artifact_spec + raise CaskInvalidError.new(@cask.token, "no source given for artifact") if source_string.nil? + @source = @cask.staged_path.join(source_string) + raise CaskInvalidError.new(@cask.token, "target required for generic artifact #{source_string}") unless target_hash.is_a?(Hash) + target_hash.assert_valid_keys(:target) + @target = Pathname.new(target_hash[:target]) + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/audio_unit_plugin.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::AudioUnitPlugin < Hbc::Artifact::Moved +module Hbc + module Artifact + class AudioUnitPlugin < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/base.rb
@@ -1,79 +1,83 @@ -class Hbc::Artifact::Base - def self.artifact_name - @artifact_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1_\2').downcase - end - - def self.artifact_english_name - @artifact_english_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1 \2') - end - - def self.artifact_english_article - @artifact_english_article ||= artifact_english_name =~ %r{^[aeiou]}i ? "an" : "a" - end - - def self.artifact_dsl_key - @artifact_dsl_key ||= artifact_name.to_sym - end - - def self.artifact_dirmethod - @artifact_dirmethod ||= "#{artifact_name}dir".to_sym - end - - def self.me?(cask) - cask.artifacts[artifact_dsl_key].any? - end - - attr_reader :force - - def zap_phase - odebug "Nothing to do. The #{self.class.artifact_name} artifact has no zap phase." - end - - # TODO: this sort of logic would make more sense in dsl.rb, or a - # constructor called from dsl.rb, so long as that isn't slow. - def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil) - # TODO: when stanza names are harmonized with class names, - # stanza may not be needed as an explicit argument - description = stanza.to_s - if key - arguments = arguments[key] - description.concat(" #{key.inspect}") - end - - # backward-compatible string value - arguments = { executable: arguments } if arguments.is_a?(String) - - # key sanity - permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :bsexec, :print_stdout, :print_stderr] - unknown_keys = arguments.keys - permitted_keys - unless unknown_keys.empty? - opoo %Q{Unknown arguments to #{description} -- #{unknown_keys.inspect} (ignored). Running "brew update; brew cleanup; brew cask cleanup" will likely fix it.} +module Hbc + module Artifact + class Base + def self.artifact_name + @artifact_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1_\2').downcase + end + + def self.artifact_english_name + @artifact_english_name ||= name.sub(%r{^.*:}, "").gsub(%r{(.)([A-Z])}, '\1 \2') + end + + def self.artifact_english_article + @artifact_english_article ||= artifact_english_name =~ %r{^[aeiou]}i ? "an" : "a" + end + + def self.artifact_dsl_key + @artifact_dsl_key ||= artifact_name.to_sym + end + + def self.artifact_dirmethod + @artifact_dirmethod ||= "#{artifact_name}dir".to_sym + end + + def self.me?(cask) + cask.artifacts[artifact_dsl_key].any? + end + + attr_reader :force + + def zap_phase + odebug "Nothing to do. The #{self.class.artifact_name} artifact has no zap phase." + end + + # TODO: this sort of logic would make more sense in dsl.rb, or a + # constructor called from dsl.rb, so long as that isn't slow. + def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil) + # TODO: when stanza names are harmonized with class names, + # stanza may not be needed as an explicit argument + description = stanza.to_s + if key + arguments = arguments[key] + description.concat(" #{key.inspect}") + end + + # backward-compatible string value + arguments = { executable: arguments } if arguments.is_a?(String) + + # key sanity + permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :bsexec, :print_stdout, :print_stderr] + unknown_keys = arguments.keys - permitted_keys + unless unknown_keys.empty? + opoo %Q{Unknown arguments to #{description} -- #{unknown_keys.inspect} (ignored). Running "brew update; brew cleanup; brew cask cleanup" will likely fix it.} + end + arguments.reject! { |k| !permitted_keys.include?(k) } + + # key warnings + override_keys = override_arguments.keys + ignored_keys = arguments.keys & override_keys + unless ignored_keys.empty? + onoe "Some arguments to #{description} will be ignored -- :#{unknown_keys.inspect} (overridden)." + end + + # extract executable + executable = arguments.key?(:executable) ? arguments.delete(:executable) : nil + + arguments = default_arguments.merge arguments + arguments.merge! override_arguments + + [executable, arguments] + end + + def summary + {} + end + + def initialize(cask, command: SystemCommand, force: false) + @cask = cask + @command = command + @force = force + end end - arguments.reject! { |k| !permitted_keys.include?(k) } - - # key warnings - override_keys = override_arguments.keys - ignored_keys = arguments.keys & override_keys - unless ignored_keys.empty? - onoe "Some arguments to #{description} will be ignored -- :#{unknown_keys.inspect} (overridden)." - end - - # extract executable - executable = arguments.key?(:executable) ? arguments.delete(:executable) : nil - - arguments = default_arguments.merge arguments - arguments.merge! override_arguments - - [executable, arguments] - end - - def summary - {} - end - - def initialize(cask, command: Hbc::SystemCommand, force: false) - @cask = cask - @command = command - @force = force end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/binary.rb
@@ -1,7 +1,11 @@ require "hbc/artifact/symlinked" -class Hbc::Artifact::Binary < Hbc::Artifact::Symlinked - def install_phase - super unless Hbc.no_binaries +module Hbc + module Artifact + class Binary < Symlinked + def install_phase + super unless Hbc.no_binaries + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/colorpicker.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::Colorpicker < Hbc::Artifact::Moved +module Hbc + module Artifact + class Colorpicker < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/font.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::Font < Hbc::Artifact::Moved +module Hbc + module Artifact + class Font < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/input_method.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::InputMethod < Hbc::Artifact::Moved +module Hbc + module Artifact + class InputMethod < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/installer.rb
@@ -1,41 +1,45 @@ require "hbc/artifact/base" -class Hbc::Artifact::Installer < Hbc::Artifact::Base - # TODO: for backward compatibility, removeme - def install - install_phase - end +module Hbc + module Artifact + class Installer < Base + # TODO: for backward compatibility, removeme + def install + install_phase + end - # TODO: for backward compatibility, removeme - def uninstall - uninstall_phase - end + # TODO: for backward compatibility, removeme + def uninstall + uninstall_phase + end - def install_phase - @cask.artifacts[self.class.artifact_dsl_key].each do |artifact| - if artifact.manual - puts <<-EOS.undent - To complete the installation of Cask #{@cask}, you must also - run the installer at + def install_phase + @cask.artifacts[self.class.artifact_dsl_key].each do |artifact| + if artifact.manual + puts <<-EOS.undent + To complete the installation of Cask #{@cask}, you must also + run the installer at - '#{@cask.staged_path.join(artifact.manual)}' + '#{@cask.staged_path.join(artifact.manual)}' - EOS - else - executable, script_arguments = self.class.read_script_arguments(artifact.script, - self.class.artifact_dsl_key.to_s, - { must_succeed: true, sudo: true }, - print_stdout: true) - ohai "Running #{self.class.artifact_dsl_key} script #{executable}" - raise Hbc::CaskInvalidError.new(@cask, "#{self.class.artifact_dsl_key} missing executable") if executable.nil? - executable_path = @cask.staged_path.join(executable) - @command.run("/bin/chmod", args: ["--", "+x", executable_path]) if File.exist?(executable_path) - @command.run(executable_path, script_arguments) + EOS + else + executable, script_arguments = self.class.read_script_arguments(artifact.script, + self.class.artifact_dsl_key.to_s, + { must_succeed: true, sudo: true }, + print_stdout: true) + ohai "Running #{self.class.artifact_dsl_key} script #{executable}" + raise CaskInvalidError.new(@cask, "#{self.class.artifact_dsl_key} missing executable") if executable.nil? + executable_path = @cask.staged_path.join(executable) + @command.run("/bin/chmod", args: ["--", "+x", executable_path]) if File.exist?(executable_path) + @command.run(executable_path, script_arguments) + end + end end - end - end - def uninstall_phase - odebug "Nothing to do. The #{self.class.artifact_dsl_key} artifact has no uninstall phase." + def uninstall_phase + odebug "Nothing to do. The #{self.class.artifact_dsl_key} artifact has no uninstall phase." + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/internet_plugin.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::InternetPlugin < Hbc::Artifact::Moved +module Hbc + module Artifact + class InternetPlugin < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/moved.rb
@@ -1,88 +1,92 @@ require "hbc/artifact/relocated" -class Hbc::Artifact::Moved < Hbc::Artifact::Relocated - def self.english_description - "#{artifact_english_name}s" - end +module Hbc + module Artifact + class Moved < Relocated + def self.english_description + "#{artifact_english_name}s" + end - def install_phase - each_artifact do |artifact| - load_specification(artifact) - next unless preflight_checks - delete if Hbc::Utils.path_occupied?(target) && force - move - end - end + def install_phase + each_artifact do |artifact| + load_specification(artifact) + next unless preflight_checks + delete if Utils.path_occupied?(target) && force + move + end + end - def uninstall_phase - each_artifact do |artifact| - load_specification(artifact) - next unless File.exist?(target) - delete - end - end + def uninstall_phase + each_artifact do |artifact| + load_specification(artifact) + next unless File.exist?(target) + delete + end + end - private + private - def each_artifact - # the sort is for predictability between Ruby versions - @cask.artifacts[self.class.artifact_dsl_key].sort.each do |artifact| - yield artifact - end - end + def each_artifact + # the sort is for predictability between Ruby versions + @cask.artifacts[self.class.artifact_dsl_key].sort.each do |artifact| + yield artifact + end + end - def move - ohai "Moving #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'" - target.dirname.mkpath - FileUtils.move(source, target) - add_altname_metadata target, source.basename.to_s - end + def move + ohai "Moving #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'" + target.dirname.mkpath + FileUtils.move(source, target) + add_altname_metadata target, source.basename.to_s + end - def preflight_checks - if Hbc::Utils.path_occupied?(target) - if force - ohai(warning_target_exists { |s| s << "overwriting." }) - else - ohai(warning_target_exists { |s| s << "not moving." }) - return false + def preflight_checks + if Utils.path_occupied?(target) + if force + ohai(warning_target_exists { |s| s << "overwriting." }) + else + ohai(warning_target_exists { |s| s << "not moving." }) + return false + end + end + unless source.exist? + message = "It seems the #{self.class.artifact_english_name} source is not there: '#{source}'" + raise CaskError, message + end + true end - end - unless source.exist? - message = "It seems the #{self.class.artifact_english_name} source is not there: '#{source}'" - raise Hbc::CaskError, message - end - true - end - def warning_target_exists - message_parts = [ - "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'", - ] - yield(message_parts) if block_given? - message_parts.join("; ") - end + def warning_target_exists + message_parts = [ + "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'", + ] + yield(message_parts) if block_given? + message_parts.join("; ") + end - def delete - ohai "Removing #{self.class.artifact_english_name}: '#{target}'" - raise Hbc::CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}" if MacOS.undeletable?(target) + def delete + ohai "Removing #{self.class.artifact_english_name}: '#{target}'" + raise CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}" if MacOS.undeletable?(target) - if force - Hbc::Utils.gain_permissions_remove(target, command: @command) - else - target.rmtree - end - end + if force + Utils.gain_permissions_remove(target, command: @command) + else + target.rmtree + end + end - def summarize_artifact(artifact_spec) - load_specification artifact_spec + def summarize_artifact(artifact_spec) + load_specification artifact_spec - if target.exist? - target_abv = " (#{target.abv})" - else - warning = "Missing #{self.class.artifact_english_name}" - warning = "#{Tty.red}#{warning}#{Tty.reset}: " - end + if target.exist? + target_abv = " (#{target.abv})" + else + warning = "Missing #{self.class.artifact_english_name}" + warning = "#{Tty.red}#{warning}#{Tty.reset}: " + end - "#{warning}#{printable_target}#{target_abv}" + "#{warning}#{printable_target}#{target_abv}" + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb
@@ -1,24 +1,28 @@ require "hbc/artifact/base" -class Hbc::Artifact::NestedContainer < Hbc::Artifact::Base - def install_phase - @cask.artifacts[:nested_container].each { |container| extract(container) } - end +module Hbc + module Artifact + class NestedContainer < Base + def install_phase + @cask.artifacts[:nested_container].each { |container| extract(container) } + end - def uninstall_phase - # no need to take action; is removed after extraction - end + def uninstall_phase + # no need to take action; is removed after extraction + end - def extract(container_relative_path) - source = @cask.staged_path.join(container_relative_path) - container = Hbc::Container.for_path(source, @command) + def extract(container_relative_path) + source = @cask.staged_path.join(container_relative_path) + container = Container.for_path(source, @command) - unless container - raise Hbc::CaskError, "Aw dang, could not identify nested container at '#{source}'" - end + unless container + raise CaskError, "Aw dang, could not identify nested container at '#{source}'" + end - ohai "Extracting nested container #{source.basename}" - container.new(@cask, source, @command).extract - FileUtils.remove_entry_secure(source) + ohai "Extracting nested container #{source.basename}" + container.new(@cask, source, @command).extract + FileUtils.remove_entry_secure(source) + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
@@ -1,53 +1,57 @@ require "hbc/artifact/base" -class Hbc::Artifact::Pkg < Hbc::Artifact::Base - attr_reader :pkg_relative_path +module Hbc + module Artifact + class Pkg < Base + attr_reader :pkg_relative_path - def self.artifact_dsl_key - :pkg - end + def self.artifact_dsl_key + :pkg + end - def load_pkg_description(pkg_description) - @pkg_relative_path = pkg_description.shift - @pkg_install_opts = pkg_description.shift - begin - if @pkg_install_opts.respond_to?(:keys) - @pkg_install_opts.assert_valid_keys(:allow_untrusted) - elsif @pkg_install_opts - raise + def load_pkg_description(pkg_description) + @pkg_relative_path = pkg_description.shift + @pkg_install_opts = pkg_description.shift + begin + if @pkg_install_opts.respond_to?(:keys) + @pkg_install_opts.assert_valid_keys(:allow_untrusted) + elsif @pkg_install_opts + raise + end + raise if pkg_description.nil? + rescue StandardError + raise CaskInvalidError.new(@cask, "Bad pkg stanza") + end end - raise if pkg_description.nil? - rescue StandardError - raise Hbc::CaskInvalidError.new(@cask, "Bad pkg stanza") - end - end - def pkg_install_opts(opt) - @pkg_install_opts[opt] if @pkg_install_opts.respond_to?(:keys) - end + def pkg_install_opts(opt) + @pkg_install_opts[opt] if @pkg_install_opts.respond_to?(:keys) + end - def install_phase - @cask.artifacts[:pkg].each { |pkg_description| run_installer(pkg_description) } - end + def install_phase + @cask.artifacts[:pkg].each { |pkg_description| run_installer(pkg_description) } + end - def uninstall_phase - # Do nothing. Must be handled explicitly by a separate :uninstall stanza. - end + def uninstall_phase + # Do nothing. Must be handled explicitly by a separate :uninstall stanza. + end - def run_installer(pkg_description) - load_pkg_description pkg_description - ohai "Running installer for #{@cask}; your password may be necessary." - ohai "Package installers may write to any location; options such as --appdir are ignored." - source = @cask.staged_path.join(pkg_relative_path) - unless source.exist? - raise Hbc::CaskError, "pkg source file not found: '#{source}'" + def run_installer(pkg_description) + load_pkg_description pkg_description + ohai "Running installer for #{@cask}; your password may be necessary." + ohai "Package installers may write to any location; options such as --appdir are ignored." + source = @cask.staged_path.join(pkg_relative_path) + unless source.exist? + raise CaskError, "pkg source file not found: '#{source}'" + end + args = [ + "-pkg", source, + "-target", "/" + ] + args << "-verboseR" if Hbc.verbose + args << "-allowUntrusted" if pkg_install_opts :allow_untrusted + @command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true) + end end - args = [ - "-pkg", source, - "-target", "/" - ] - args << "-verboseR" if Hbc.verbose - args << "-allowUntrusted" if pkg_install_opts :allow_untrusted - @command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true) end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/postflight_block.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/abstract_flight_block" -class Hbc::Artifact::PostflightBlock < Hbc::Artifact::AbstractFlightBlock +module Hbc + module Artifact + class PostflightBlock < AbstractFlightBlock + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/preflight_block.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/abstract_flight_block" -class Hbc::Artifact::PreflightBlock < Hbc::Artifact::AbstractFlightBlock +module Hbc + module Artifact + class PreflightBlock < AbstractFlightBlock + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/prefpane.rb
@@ -1,7 +1,11 @@ require "hbc/artifact/moved" -class Hbc::Artifact::Prefpane < Hbc::Artifact::Moved - def self.artifact_english_name - "Preference Pane" +module Hbc + module Artifact + class Prefpane < Moved + def self.artifact_english_name + "Preference Pane" + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/qlplugin.rb
@@ -1,21 +1,25 @@ require "hbc/artifact/moved" -class Hbc::Artifact::Qlplugin < Hbc::Artifact::Moved - def self.artifact_english_name - "QuickLook Plugin" - end +module Hbc + module Artifact + class Qlplugin < Moved + def self.artifact_english_name + "QuickLook Plugin" + end - def install_phase - super - reload_quicklook - end + def install_phase + super + reload_quicklook + end - def uninstall_phase - super - reload_quicklook - end + def uninstall_phase + super + reload_quicklook + end - def reload_quicklook - @command.run!("/usr/bin/qlmanage", args: ["-r"]) + def reload_quicklook + @command.run!("/usr/bin/qlmanage", args: ["-r"]) + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/relocated.rb
@@ -1,53 +1,57 @@ require "hbc/artifact/base" -class Hbc::Artifact::Relocated < Hbc::Artifact::Base - def summary - { - english_description: self.class.english_description, - contents: @cask.artifacts[self.class.artifact_dsl_key].map(&method(:summarize_artifact)).compact, - } - end - - attr_reader :source, :target - - def printable_target - target.to_s.sub(%r{^#{ENV['HOME']}(#{File::SEPARATOR}|$)}, "~/") - end - - ALT_NAME_ATTRIBUTE = "com.apple.metadata:kMDItemAlternateNames".freeze - - # Try to make the asset searchable under the target name. Spotlight - # respects this attribute for many filetypes, but ignores it for App - # bundles. Alfred 2.2 respects it even for App bundles. - def add_altname_metadata(file, altname) - return if altname.casecmp(file.basename).zero? - odebug "Adding #{ALT_NAME_ATTRIBUTE} metadata" - altnames = @command.run("/usr/bin/xattr", - args: ["-p", ALT_NAME_ATTRIBUTE, file.to_s], - print_stderr: false).stdout.sub(%r{\A\((.*)\)\Z}, '\1') - odebug "Existing metadata is: '#{altnames}'" - altnames.concat(", ") unless altnames.empty? - altnames.concat(%Q{"#{altname}"}) - altnames = "(#{altnames})" - - # Some packges are shipped as u=rx (e.g. Bitcoin Core) - @command.run!("/bin/chmod", args: ["--", "u=rwx", file.to_s, file.realpath.to_s]) - - @command.run!("/usr/bin/xattr", - args: ["-w", ALT_NAME_ATTRIBUTE, altnames, file.to_s], - print_stderr: false) - end - - def load_specification(artifact_spec) - source_string, target_hash = artifact_spec - raise Hbc::CaskInvalidError if source_string.nil? - @source = @cask.staged_path.join(source_string) - if target_hash - raise Hbc::CaskInvalidError unless target_hash.respond_to?(:keys) - target_hash.assert_valid_keys(:target) - @target = Hbc.send(self.class.artifact_dirmethod).join(target_hash[:target]) - else - @target = Hbc.send(self.class.artifact_dirmethod).join(source.basename) +module Hbc + module Artifact + class Relocated < Base + def summary + { + english_description: self.class.english_description, + contents: @cask.artifacts[self.class.artifact_dsl_key].map(&method(:summarize_artifact)).compact, + } + end + + attr_reader :source, :target + + def printable_target + target.to_s.sub(%r{^#{ENV['HOME']}(#{File::SEPARATOR}|$)}, "~/") + end + + ALT_NAME_ATTRIBUTE = "com.apple.metadata:kMDItemAlternateNames".freeze + + # Try to make the asset searchable under the target name. Spotlight + # respects this attribute for many filetypes, but ignores it for App + # bundles. Alfred 2.2 respects it even for App bundles. + def add_altname_metadata(file, altname) + return if altname.casecmp(file.basename).zero? + odebug "Adding #{ALT_NAME_ATTRIBUTE} metadata" + altnames = @command.run("/usr/bin/xattr", + args: ["-p", ALT_NAME_ATTRIBUTE, file.to_s], + print_stderr: false).stdout.sub(%r{\A\((.*)\)\Z}, '\1') + odebug "Existing metadata is: '#{altnames}'" + altnames.concat(", ") unless altnames.empty? + altnames.concat(%Q{"#{altname}"}) + altnames = "(#{altnames})" + + # Some packges are shipped as u=rx (e.g. Bitcoin Core) + @command.run!("/bin/chmod", args: ["--", "u=rwx", file.to_s, file.realpath.to_s]) + + @command.run!("/usr/bin/xattr", + args: ["-w", ALT_NAME_ATTRIBUTE, altnames, file.to_s], + print_stderr: false) + end + + def load_specification(artifact_spec) + source_string, target_hash = artifact_spec + raise CaskInvalidError if source_string.nil? + @source = @cask.staged_path.join(source_string) + if target_hash + raise CaskInvalidError unless target_hash.respond_to?(:keys) + target_hash.assert_valid_keys(:target) + @target = Hbc.send(self.class.artifact_dirmethod).join(target_hash[:target]) + else + @target = Hbc.send(self.class.artifact_dirmethod).join(source.basename) + end + end end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/screen_saver.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::ScreenSaver < Hbc::Artifact::Moved +module Hbc + module Artifact + class ScreenSaver < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/service.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::Service < Hbc::Artifact::Moved +module Hbc + module Artifact + class Service < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/stage_only.rb
@@ -1,15 +1,19 @@ require "hbc/artifact/base" -class Hbc::Artifact::StageOnly < Hbc::Artifact::Base - def self.artifact_dsl_key - :stage_only - end +module Hbc + module Artifact + class StageOnly < Base + def self.artifact_dsl_key + :stage_only + end - def install_phase - # do nothing - end + def install_phase + # do nothing + end - def uninstall_phase - # do nothing + def uninstall_phase + # do nothing + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/suite.rb
@@ -1,11 +1,15 @@ require "hbc/artifact/moved" -class Hbc::Artifact::Suite < Hbc::Artifact::Moved - def self.artifact_english_name - "App Suite" - end +module Hbc + module Artifact + class Suite < Moved + def self.artifact_english_name + "App Suite" + end - def self.artifact_dirmethod - :appdir + def self.artifact_dirmethod + :appdir + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb
@@ -1,65 +1,69 @@ require "hbc/artifact/relocated" -class Hbc::Artifact::Symlinked < Hbc::Artifact::Relocated - def self.link_type_english_name - "Symlink" - end +module Hbc + module Artifact + class Symlinked < Relocated + def self.link_type_english_name + "Symlink" + end - def self.english_description - "#{artifact_english_name} #{link_type_english_name}s" - end + def self.english_description + "#{artifact_english_name} #{link_type_english_name}s" + end - def self.islink?(path) - path.symlink? - end + def self.islink?(path) + path.symlink? + end - def link(artifact_spec) - load_specification artifact_spec - return unless preflight_checks(source, target) - ohai "#{self.class.link_type_english_name}ing #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'" - create_filesystem_link(source, target) - end + def link(artifact_spec) + load_specification artifact_spec + return unless preflight_checks(source, target) + ohai "#{self.class.link_type_english_name}ing #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'" + create_filesystem_link(source, target) + end - def unlink(artifact_spec) - load_specification artifact_spec - return unless self.class.islink?(target) - ohai "Removing #{self.class.artifact_english_name} #{self.class.link_type_english_name.downcase}: '#{target}'" - target.delete - end + def unlink(artifact_spec) + load_specification artifact_spec + return unless self.class.islink?(target) + ohai "Removing #{self.class.artifact_english_name} #{self.class.link_type_english_name.downcase}: '#{target}'" + target.delete + end - def install_phase - @cask.artifacts[self.class.artifact_dsl_key].each(&method(:link)) - end + def install_phase + @cask.artifacts[self.class.artifact_dsl_key].each(&method(:link)) + end - def uninstall_phase - @cask.artifacts[self.class.artifact_dsl_key].each(&method(:unlink)) - end + def uninstall_phase + @cask.artifacts[self.class.artifact_dsl_key].each(&method(:unlink)) + end - def preflight_checks(source, target) - if target.exist? && !self.class.islink?(target) - ohai "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'; not linking." - return false - end - unless source.exist? - raise Hbc::CaskError, "It seems the #{self.class.link_type_english_name.downcase} source is not there: '#{source}'" - end - true - end + def preflight_checks(source, target) + if target.exist? && !self.class.islink?(target) + ohai "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'; not linking." + return false + end + unless source.exist? + raise CaskError, "It seems the #{self.class.link_type_english_name.downcase} source is not there: '#{source}'" + end + true + end - def create_filesystem_link(source, target) - Pathname.new(target).dirname.mkpath - @command.run!("/bin/ln", args: ["-hfs", "--", source, target]) - add_altname_metadata source, target.basename.to_s - end + def create_filesystem_link(source, target) + Pathname.new(target).dirname.mkpath + @command.run!("/bin/ln", args: ["-hfs", "--", source, target]) + add_altname_metadata source, target.basename.to_s + end - def summarize_artifact(artifact_spec) - load_specification artifact_spec + def summarize_artifact(artifact_spec) + load_specification artifact_spec - return unless self.class.islink?(target) + return unless self.class.islink?(target) - link_description = "#{Tty.red}Broken Link#{Tty.reset}: " unless target.exist? - target_readlink_abv = " (#{target.readlink.abv})" if target.readlink.exist? + link_description = "#{Tty.red}Broken Link#{Tty.reset}: " unless target.exist? + target_readlink_abv = " (#{target.readlink.abv})" if target.readlink.exist? - "#{link_description}#{printable_target} -> #{target.readlink}#{target_readlink_abv}" + "#{link_description}#{printable_target} -> #{target.readlink}#{target_readlink_abv}" + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/uninstall.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/uninstall_base" -class Hbc::Artifact::Uninstall < Hbc::Artifact::UninstallBase +module Hbc + module Artifact + class Uninstall < UninstallBase + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb
@@ -2,248 +2,252 @@ require "hbc/artifact/base" -class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base - # TODO: 500 is also hardcoded in cask/pkg.rb, but much of - # that logic is probably in the wrong location - - PATH_ARG_SLICE_SIZE = 500 - - ORDERED_DIRECTIVES = [ - :early_script, - :launchctl, - :quit, - :signal, - :login_item, - :kext, - :script, - :pkgutil, - :delete, - :trash, - :rmdir, - ].freeze - - # TODO: these methods were consolidated here from separate - # sources and should be refactored for consistency - - def self.expand_path_strings(path_strings) - path_strings.map { |path_string| - path_string.start_with?("~") ? Pathname.new(path_string).expand_path : Pathname.new(path_string) - } - end +module Hbc + module Artifact + class UninstallBase < Base + # TODO: 500 is also hardcoded in cask/pkg.rb, but much of + # that logic is probably in the wrong location + + PATH_ARG_SLICE_SIZE = 500 + + ORDERED_DIRECTIVES = [ + :early_script, + :launchctl, + :quit, + :signal, + :login_item, + :kext, + :script, + :pkgutil, + :delete, + :trash, + :rmdir, + ].freeze + + # TODO: these methods were consolidated here from separate + # sources and should be refactored for consistency + + def self.expand_path_strings(path_strings) + path_strings.map { |path_string| + path_string.start_with?("~") ? Pathname.new(path_string).expand_path : Pathname.new(path_string) + } + end - def self.remove_relative_path_strings(action, path_strings) - relative = path_strings.map { |path_string| - path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string) - }.compact - relative.each do |path_string| - opoo "Skipping #{action} for relative path #{path_string}" - end - path_strings - relative - end + def self.remove_relative_path_strings(action, path_strings) + relative = path_strings.map { |path_string| + path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string) + }.compact + relative.each do |path_string| + opoo "Skipping #{action} for relative path #{path_string}" + end + path_strings - relative + end - def self.remove_undeletable_path_strings(action, path_strings) - undeletable = path_strings.map { |path_string| - path_string if MacOS.undeletable?(Pathname.new(path_string)) - }.compact - undeletable.each do |path_string| - opoo "Skipping #{action} for undeletable path #{path_string}" - end - path_strings - undeletable - end + def self.remove_undeletable_path_strings(action, path_strings) + undeletable = path_strings.map { |path_string| + path_string if MacOS.undeletable?(Pathname.new(path_string)) + }.compact + undeletable.each do |path_string| + opoo "Skipping #{action} for undeletable path #{path_string}" + end + path_strings - undeletable + end - def install_phase - odebug "Nothing to do. The uninstall artifact has no install phase." - end + def install_phase + odebug "Nothing to do. The uninstall artifact has no install phase." + end - def uninstall_phase - dispatch_uninstall_directives - end + def uninstall_phase + dispatch_uninstall_directives + end - def dispatch_uninstall_directives(expand_tilde = true) - directives_set = @cask.artifacts[stanza] - ohai "Running #{stanza} process for #{@cask}; your password may be necessary" + def dispatch_uninstall_directives(expand_tilde = true) + directives_set = @cask.artifacts[stanza] + ohai "Running #{stanza} process for #{@cask}; your password may be necessary" - directives_set.each do |directives| - warn_for_unknown_directives(directives) - end + directives_set.each do |directives| + warn_for_unknown_directives(directives) + end - ORDERED_DIRECTIVES.each do |directive_sym| - directives_set.select { |h| h.key?(directive_sym) }.each do |directives| - args = [directives] - args << expand_tilde if [:delete, :trash, :rmdir].include?(directive_sym) - send("uninstall_#{directive_sym}", *args) + ORDERED_DIRECTIVES.each do |directive_sym| + directives_set.select { |h| h.key?(directive_sym) }.each do |directives| + args = [directives] + args << expand_tilde if [:delete, :trash, :rmdir].include?(directive_sym) + send("uninstall_#{directive_sym}", *args) + end + end end - end - end - private + private - def stanza - self.class.artifact_dsl_key - end + def stanza + self.class.artifact_dsl_key + end - def warn_for_unknown_directives(directives) - unknown_keys = directives.keys - ORDERED_DIRECTIVES - return if unknown_keys.empty? - opoo %Q{Unknown arguments to #{stanza} -- #{unknown_keys.inspect}. Running "brew update; brew cleanup; brew cask cleanup" will likely fix it.} - end + def warn_for_unknown_directives(directives) + unknown_keys = directives.keys - ORDERED_DIRECTIVES + return if unknown_keys.empty? + opoo %Q{Unknown arguments to #{stanza} -- #{unknown_keys.inspect}. Running "brew update; brew cleanup; brew cask cleanup" will likely fix it.} + end - # Preserve prior functionality of script which runs first. Should rarely be needed. - # :early_script should not delete files, better defer that to :script. - # If Cask writers never need :early_script it may be removed in the future. - def uninstall_early_script(directives) - uninstall_script(directives, directive_name: :early_script) - end + # Preserve prior functionality of script which runs first. Should rarely be needed. + # :early_script should not delete files, better defer that to :script. + # If Cask writers never need :early_script it may be removed in the future. + def uninstall_early_script(directives) + uninstall_script(directives, directive_name: :early_script) + end - # :launchctl must come before :quit/:signal for cases where app would instantly re-launch - def uninstall_launchctl(directives) - Array(directives[:launchctl]).each do |service| - ohai "Removing launchctl service #{service}" - [false, true].each do |with_sudo| - plist_status = @command.run("/bin/launchctl", args: ["list", service], sudo: with_sudo, print_stderr: false).stdout - if plist_status =~ %r{^\{} - @command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo) - sleep 1 + # :launchctl must come before :quit/:signal for cases where app would instantly re-launch + def uninstall_launchctl(directives) + Array(directives[:launchctl]).each do |service| + ohai "Removing launchctl service #{service}" + [false, true].each do |with_sudo| + plist_status = @command.run("/bin/launchctl", args: ["list", service], sudo: with_sudo, print_stderr: false).stdout + if plist_status =~ %r{^\{} + @command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo) + sleep 1 + end + paths = ["/Library/LaunchAgents/#{service}.plist", + "/Library/LaunchDaemons/#{service}.plist"] + paths.each { |elt| elt.prepend(ENV["HOME"]) } unless with_sudo + paths = paths.map { |elt| Pathname(elt) }.select(&:exist?) + paths.each do |path| + @command.run!("/bin/rm", args: ["-f", "--", path], sudo: with_sudo) + end + # undocumented and untested: pass a path to uninstall :launchctl + next unless Pathname(service).exist? + @command.run!("/bin/launchctl", args: ["unload", "-w", "--", service], sudo: with_sudo) + @command.run!("/bin/rm", args: ["-f", "--", service], sudo: with_sudo) + sleep 1 + end end - paths = ["/Library/LaunchAgents/#{service}.plist", - "/Library/LaunchDaemons/#{service}.plist"] - paths.each { |elt| elt.prepend(ENV["HOME"]) } unless with_sudo - paths = paths.map { |elt| Pathname(elt) }.select(&:exist?) - paths.each do |path| - @command.run!("/bin/rm", args: ["-f", "--", path], sudo: with_sudo) + end + + # :quit/:signal must come before :kext so the kext will not be in use by a running process + def uninstall_quit(directives) + Array(directives[:quit]).each do |id| + ohai "Quitting application ID #{id}" + num_running = count_running_processes(id) + next unless num_running > 0 + @command.run!("/usr/bin/osascript", args: ["-e", %Q{tell application id "#{id}" to quit}], sudo: true) + sleep 3 end - # undocumented and untested: pass a path to uninstall :launchctl - next unless Pathname(service).exist? - @command.run!("/bin/launchctl", args: ["unload", "-w", "--", service], sudo: with_sudo) - @command.run!("/bin/rm", args: ["-f", "--", service], sudo: with_sudo) - sleep 1 end - end - end - # :quit/:signal must come before :kext so the kext will not be in use by a running process - def uninstall_quit(directives) - Array(directives[:quit]).each do |id| - ohai "Quitting application ID #{id}" - num_running = count_running_processes(id) - next unless num_running > 0 - @command.run!("/usr/bin/osascript", args: ["-e", %Q{tell application id "#{id}" to quit}], sudo: true) - sleep 3 - end - end + # :signal should come after :quit so it can be used as a backup when :quit fails + def uninstall_signal(directives) + Array(directives[:signal]).flatten.each_slice(2) do |pair| + raise CaskInvalidError.new(@cask, "Each #{stanza} :signal must have 2 elements.") unless pair.length == 2 + signal, id = pair + ohai "Signalling '#{signal}' to application ID '#{id}'" + pids = get_unix_pids(id) + next unless pids.any? + # Note that unlike :quit, signals are sent from the current user (not + # upgraded to the superuser). This is a todo item for the future, but + # there should be some additional thought/safety checks about that, as a + # misapplied "kill" by root could bring down the system. The fact that we + # learned the pid from AppleScript is already some degree of protection, + # though indirect. + odebug "Unix ids are #{pids.inspect} for processes with bundle identifier #{id}" + Process.kill(signal, *pids) + sleep 3 + end + end - # :signal should come after :quit so it can be used as a backup when :quit fails - def uninstall_signal(directives) - Array(directives[:signal]).flatten.each_slice(2) do |pair| - raise Hbc::CaskInvalidError.new(@cask, "Each #{stanza} :signal must have 2 elements.") unless pair.length == 2 - signal, id = pair - ohai "Signalling '#{signal}' to application ID '#{id}'" - pids = get_unix_pids(id) - next unless pids.any? - # Note that unlike :quit, signals are sent from the current user (not - # upgraded to the superuser). This is a todo item for the future, but - # there should be some additional thought/safety checks about that, as a - # misapplied "kill" by root could bring down the system. The fact that we - # learned the pid from AppleScript is already some degree of protection, - # though indirect. - odebug "Unix ids are #{pids.inspect} for processes with bundle identifier #{id}" - Process.kill(signal, *pids) - sleep 3 - end - end + def count_running_processes(bundle_id) + @command.run!("/usr/bin/osascript", + args: ["-e", %Q{tell application "System Events" to count processes whose bundle identifier is "#{bundle_id}"}], + sudo: true).stdout.to_i + end - def count_running_processes(bundle_id) - @command.run!("/usr/bin/osascript", - args: ["-e", %Q{tell application "System Events" to count processes whose bundle identifier is "#{bundle_id}"}], - sudo: true).stdout.to_i - end + def get_unix_pids(bundle_id) + pid_string = @command.run!("/usr/bin/osascript", + args: ["-e", %Q{tell application "System Events" to get the unix id of every process whose bundle identifier is "#{bundle_id}"}], + sudo: true).stdout.chomp + return [] unless pid_string =~ %r{\A\d+(?:\s*,\s*\d+)*\Z} # sanity check + pid_string.split(%r{\s*,\s*}).map(&:strip).map(&:to_i) + end - def get_unix_pids(bundle_id) - pid_string = @command.run!("/usr/bin/osascript", - args: ["-e", %Q{tell application "System Events" to get the unix id of every process whose bundle identifier is "#{bundle_id}"}], - sudo: true).stdout.chomp - return [] unless pid_string =~ %r{\A\d+(?:\s*,\s*\d+)*\Z} # sanity check - pid_string.split(%r{\s*,\s*}).map(&:strip).map(&:to_i) - end + def uninstall_login_item(directives) + Array(directives[:login_item]).each do |name| + ohai "Removing login item #{name}" + @command.run!("/usr/bin/osascript", + args: ["-e", %Q{tell application "System Events" to delete every login item whose name is "#{name}"}], + sudo: false) + sleep 1 + end + end - def uninstall_login_item(directives) - Array(directives[:login_item]).each do |name| - ohai "Removing login item #{name}" - @command.run!("/usr/bin/osascript", - args: ["-e", %Q{tell application "System Events" to delete every login item whose name is "#{name}"}], - sudo: false) - sleep 1 - end - end + # :kext should be unloaded before attempting to delete the relevant file + def uninstall_kext(directives) + Array(directives[:kext]).each do |kext| + ohai "Unloading kernel extension #{kext}" + is_loaded = @command.run!("/usr/sbin/kextstat", args: ["-l", "-b", kext], sudo: true).stdout + if is_loaded.length > 1 + @command.run!("/sbin/kextunload", args: ["-b", kext], sudo: true) + sleep 1 + end + end + end - # :kext should be unloaded before attempting to delete the relevant file - def uninstall_kext(directives) - Array(directives[:kext]).each do |kext| - ohai "Unloading kernel extension #{kext}" - is_loaded = @command.run!("/usr/sbin/kextstat", args: ["-l", "-b", kext], sudo: true).stdout - if is_loaded.length > 1 - @command.run!("/sbin/kextunload", args: ["-b", kext], sudo: true) + # :script must come before :pkgutil, :delete, or :trash so that the script file is not already deleted + def uninstall_script(directives, directive_name: :script) + executable, script_arguments = self.class.read_script_arguments(directives, + "uninstall", + { must_succeed: true, sudo: true }, + { print_stdout: true }, + directive_name) + ohai "Running uninstall script #{executable}" + raise CaskInvalidError.new(@cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil? + executable_path = @cask.staged_path.join(executable) + @command.run("/bin/chmod", args: ["--", "+x", executable_path]) if File.exist?(executable_path) + @command.run(executable_path, script_arguments) sleep 1 end - end - end - - # :script must come before :pkgutil, :delete, or :trash so that the script file is not already deleted - def uninstall_script(directives, directive_name: :script) - executable, script_arguments = self.class.read_script_arguments(directives, - "uninstall", - { must_succeed: true, sudo: true }, - { print_stdout: true }, - directive_name) - ohai "Running uninstall script #{executable}" - raise Hbc::CaskInvalidError.new(@cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil? - executable_path = @cask.staged_path.join(executable) - @command.run("/bin/chmod", args: ["--", "+x", executable_path]) if File.exist?(executable_path) - @command.run(executable_path, script_arguments) - sleep 1 - end - def uninstall_pkgutil(directives) - ohai "Removing files from pkgutil Bill-of-Materials" - Array(directives[:pkgutil]).each do |regexp| - pkgs = Hbc::Pkg.all_matching(regexp, @command) - pkgs.each(&:uninstall) - end - end + def uninstall_pkgutil(directives) + ohai "Removing files from pkgutil Bill-of-Materials" + Array(directives[:pkgutil]).each do |regexp| + pkgs = Hbc::Pkg.all_matching(regexp, @command) + pkgs.each(&:uninstall) + end + end - def uninstall_delete(directives, expand_tilde = true) - Array(directives[:delete]).concat(Array(directives[:trash])).flatten.each_slice(PATH_ARG_SLICE_SIZE) do |path_slice| - ohai "Removing files: #{path_slice.utf8_inspect}" - path_slice = self.class.expand_path_strings(path_slice) if expand_tilde - path_slice = self.class.remove_relative_path_strings(:delete, path_slice) - path_slice = self.class.remove_undeletable_path_strings(:delete, path_slice) - @command.run!("/bin/rm", args: path_slice.unshift("-rf", "--"), sudo: true) - end - end + def uninstall_delete(directives, expand_tilde = true) + Array(directives[:delete]).concat(Array(directives[:trash])).flatten.each_slice(PATH_ARG_SLICE_SIZE) do |path_slice| + ohai "Removing files: #{path_slice.utf8_inspect}" + path_slice = self.class.expand_path_strings(path_slice) if expand_tilde + path_slice = self.class.remove_relative_path_strings(:delete, path_slice) + path_slice = self.class.remove_undeletable_path_strings(:delete, path_slice) + @command.run!("/bin/rm", args: path_slice.unshift("-rf", "--"), sudo: true) + end + end - # :trash functionality is stubbed as a synonym for :delete - # TODO: make :trash work differently, moving files to the Trash - def uninstall_trash(directives, expand_tilde = true) - uninstall_delete(directives, expand_tilde) - end + # :trash functionality is stubbed as a synonym for :delete + # TODO: make :trash work differently, moving files to the Trash + def uninstall_trash(directives, expand_tilde = true) + uninstall_delete(directives, expand_tilde) + end - def uninstall_rmdir(directives, expand_tilde = true) - Array(directives[:rmdir]).flatten.each do |directory| - directory = self.class.expand_path_strings([directory]).first if expand_tilde - directory = self.class.remove_relative_path_strings(:rmdir, [directory]).first - directory = self.class.remove_undeletable_path_strings(:rmdir, [directory]).first - next if directory.to_s.empty? - ohai "Removing directory if empty: #{directory.to_s.utf8_inspect}" - directory = Pathname.new(directory) - next unless directory.exist? - @command.run!("/bin/rm", - args: ["-f", "--", directory.join(".DS_Store")], - sudo: true, - print_stderr: false) - @command.run("/bin/rmdir", - args: ["--", directory], - sudo: true, - print_stderr: false) + def uninstall_rmdir(directives, expand_tilde = true) + Array(directives[:rmdir]).flatten.each do |directory| + directory = self.class.expand_path_strings([directory]).first if expand_tilde + directory = self.class.remove_relative_path_strings(:rmdir, [directory]).first + directory = self.class.remove_undeletable_path_strings(:rmdir, [directory]).first + next if directory.to_s.empty? + ohai "Removing directory if empty: #{directory.to_s.utf8_inspect}" + directory = Pathname.new(directory) + next unless directory.exist? + @command.run!("/bin/rm", + args: ["-f", "--", directory.join(".DS_Store")], + sudo: true, + print_stderr: false) + @command.run("/bin/rmdir", + args: ["--", directory], + sudo: true, + print_stderr: false) + end + end end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/vst3_plugin.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::Vst3Plugin < Hbc::Artifact::Moved +module Hbc + module Artifact + class Vst3Plugin < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/vst_plugin.rb
@@ -1,4 +1,8 @@ require "hbc/artifact/moved" -class Hbc::Artifact::VstPlugin < Hbc::Artifact::Moved +module Hbc + module Artifact + class VstPlugin < Moved + end + end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/artifact/zap.rb
@@ -1,16 +1,20 @@ require "hbc/artifact/uninstall_base" -class Hbc::Artifact::Zap < Hbc::Artifact::UninstallBase - def install_phase - odebug "Nothing to do. The zap artifact has no install phase." - end +module Hbc + module Artifact + class Zap < UninstallBase + def install_phase + odebug "Nothing to do. The zap artifact has no install phase." + end - def uninstall_phase - odebug "Nothing to do. The zap artifact has no uninstall phase." - end + def uninstall_phase + odebug "Nothing to do. The zap artifact has no uninstall phase." + end - def zap_phase - expand_tilde = true - dispatch_uninstall_directives(expand_tilde) + def zap_phase + expand_tilde = true + dispatch_uninstall_directives(expand_tilde) + end + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/audit.rb
@@ -2,215 +2,217 @@ require "hbc/download" require "digest" -class Hbc::Audit - include Hbc::Checkable +module Hbc + class Audit + include Checkable - attr_reader :cask, :download + attr_reader :cask, :download - def initialize(cask, download: false, check_token_conflicts: false, command: Hbc::SystemCommand) - @cask = cask - @download = download - @check_token_conflicts = check_token_conflicts - @command = command - end + def initialize(cask, download: false, check_token_conflicts: false, command: SystemCommand) + @cask = cask + @download = download + @check_token_conflicts = check_token_conflicts + @command = command + end - def check_token_conflicts? - @check_token_conflicts - end + def check_token_conflicts? + @check_token_conflicts + end - def run! - check_required_stanzas - check_version - check_sha256 - check_appcast - check_url - check_generic_artifacts - check_token_conflicts - check_download - self - rescue StandardError => e - odebug "#{e.message}\n#{e.backtrace.join("\n")}" - add_error "exception while auditing #{cask}: #{e.message}" - self - end + def run! + check_required_stanzas + check_version + check_sha256 + check_appcast + check_url + check_generic_artifacts + check_token_conflicts + check_download + self + rescue StandardError => e + odebug "#{e.message}\n#{e.backtrace.join("\n")}" + add_error "exception while auditing #{cask}: #{e.message}" + self + end - def success? - !(errors? || warnings?) - end + def success? + !(errors? || warnings?) + end - def summary_header - "audit for #{cask}" - end + def summary_header + "audit for #{cask}" + end - private + private - def check_required_stanzas - odebug "Auditing required stanzas" - %i{version sha256 url homepage}.each do |sym| - add_error "a #{sym} stanza is required" unless cask.send(sym) + def check_required_stanzas + odebug "Auditing required stanzas" + %i{version sha256 url homepage}.each do |sym| + add_error "a #{sym} stanza is required" unless cask.send(sym) + end + add_error "a license stanza is required (:unknown is OK)" unless cask.license + add_error "at least one name stanza is required" if cask.name.empty? + # TODO: specific DSL knowledge should not be spread around in various files like this + # TODO: nested_container should not still be a pseudo-artifact at this point + installable_artifacts = cask.artifacts.reject { |k| [:uninstall, :zap, :nested_container].include?(k) } + add_error "at least one activatable artifact stanza is required" if installable_artifacts.empty? end - add_error "a license stanza is required (:unknown is OK)" unless cask.license - add_error "at least one name stanza is required" if cask.name.empty? - # TODO: specific DSL knowledge should not be spread around in various files like this - # TODO: nested_container should not still be a pseudo-artifact at this point - installable_artifacts = cask.artifacts.reject { |k| [:uninstall, :zap, :nested_container].include?(k) } - add_error "at least one activatable artifact stanza is required" if installable_artifacts.empty? - end - def check_version - return unless cask.version - check_no_string_version_latest - end + def check_version + return unless cask.version + check_no_string_version_latest + end - def check_no_string_version_latest - odebug "Verifying version :latest does not appear as a string ('latest')" - return unless cask.version.raw_version == "latest" - add_error "you should use version :latest instead of version 'latest'" - end + def check_no_string_version_latest + odebug "Verifying version :latest does not appear as a string ('latest')" + return unless cask.version.raw_version == "latest" + add_error "you should use version :latest instead of version 'latest'" + end - def check_sha256 - return unless cask.sha256 - check_sha256_no_check_if_latest - check_sha256_actually_256 - check_sha256_invalid - end + def check_sha256 + return unless cask.sha256 + check_sha256_no_check_if_latest + check_sha256_actually_256 + check_sha256_invalid + end - def check_sha256_no_check_if_latest - odebug "Verifying sha256 :no_check with version :latest" - return unless cask.version.latest? && cask.sha256 != :no_check - add_error "you should use sha256 :no_check when version is :latest" - end + def check_sha256_no_check_if_latest + odebug "Verifying sha256 :no_check with version :latest" + return unless cask.version.latest? && cask.sha256 != :no_check + add_error "you should use sha256 :no_check when version is :latest" + end - def check_sha256_actually_256(sha256: cask.sha256, stanza: "sha256") - odebug "Verifying #{stanza} string is a legal SHA-256 digest" - return unless sha256.is_a?(String) - return if sha256.length == 64 && sha256[%r{^[0-9a-f]+$}i] - add_error "#{stanza} string must be of 64 hexadecimal characters" - end + def check_sha256_actually_256(sha256: cask.sha256, stanza: "sha256") + odebug "Verifying #{stanza} string is a legal SHA-256 digest" + return unless sha256.is_a?(String) + return if sha256.length == 64 && sha256[%r{^[0-9a-f]+$}i] + add_error "#{stanza} string must be of 64 hexadecimal characters" + end - def check_sha256_invalid(sha256: cask.sha256, stanza: "sha256") - odebug "Verifying #{stanza} is not a known invalid value" - empty_sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - return unless sha256 == empty_sha256 - add_error "cannot use the sha256 for an empty string in #{stanza}: #{empty_sha256}" - end + def check_sha256_invalid(sha256: cask.sha256, stanza: "sha256") + odebug "Verifying #{stanza} is not a known invalid value" + empty_sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + return unless sha256 == empty_sha256 + add_error "cannot use the sha256 for an empty string in #{stanza}: #{empty_sha256}" + end - def check_appcast - return unless cask.appcast - odebug "Auditing appcast" - check_appcast_has_checkpoint - return unless cask.appcast.checkpoint - check_sha256_actually_256(sha256: cask.appcast.checkpoint, stanza: "appcast :checkpoint") - check_sha256_invalid(sha256: cask.appcast.checkpoint, stanza: "appcast :checkpoint") - return unless download - check_appcast_http_code - check_appcast_checkpoint_accuracy - end + def check_appcast + return unless cask.appcast + odebug "Auditing appcast" + check_appcast_has_checkpoint + return unless cask.appcast.checkpoint + check_sha256_actually_256(sha256: cask.appcast.checkpoint, stanza: "appcast :checkpoint") + check_sha256_invalid(sha256: cask.appcast.checkpoint, stanza: "appcast :checkpoint") + return unless download + check_appcast_http_code + check_appcast_checkpoint_accuracy + end - def check_appcast_has_checkpoint - odebug "Verifying appcast has :checkpoint key" - add_error "a checkpoint sha256 is required for appcast" unless cask.appcast.checkpoint - end + def check_appcast_has_checkpoint + odebug "Verifying appcast has :checkpoint key" + add_error "a checkpoint sha256 is required for appcast" unless cask.appcast.checkpoint + end - def check_appcast_http_code - odebug "Verifying appcast returns 200 HTTP response code" - result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--output", "/dev/null", "--write-out", "%{http_code}", cask.appcast], print_stderr: false) - if result.success? - http_code = result.stdout.chomp - add_warning "unexpected HTTP response code retrieving appcast: #{http_code}" unless http_code == "200" - else - add_warning "error retrieving appcast: #{result.stderr}" + def check_appcast_http_code + odebug "Verifying appcast returns 200 HTTP response code" + result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--output", "/dev/null", "--write-out", "%{http_code}", cask.appcast], print_stderr: false) + if result.success? + http_code = result.stdout.chomp + add_warning "unexpected HTTP response code retrieving appcast: #{http_code}" unless http_code == "200" + else + add_warning "error retrieving appcast: #{result.stderr}" + end end - end - def check_appcast_checkpoint_accuracy - odebug "Verifying appcast checkpoint is accurate" - result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, cask.appcast], print_stderr: false) - if result.success? - processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}, "") - # This step is necessary to replicate running `sed` from the command line - processed_appcast_text << "\n" unless processed_appcast_text.end_with?("\n") - expected = cask.appcast.checkpoint - actual = Digest::SHA2.hexdigest(processed_appcast_text) - add_warning <<-EOS.undent unless expected == actual - appcast checkpoint mismatch - Expected: #{expected} - Actual: #{actual} - EOS - else - add_warning "error retrieving appcast: #{result.stderr}" + def check_appcast_checkpoint_accuracy + odebug "Verifying appcast checkpoint is accurate" + result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, cask.appcast], print_stderr: false) + if result.success? + processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}, "") + # This step is necessary to replicate running `sed` from the command line + processed_appcast_text << "\n" unless processed_appcast_text.end_with?("\n") + expected = cask.appcast.checkpoint + actual = Digest::SHA2.hexdigest(processed_appcast_text) + add_warning <<-EOS.undent unless expected == actual + appcast checkpoint mismatch + Expected: #{expected} + Actual: #{actual} + EOS + else + add_warning "error retrieving appcast: #{result.stderr}" + end end - end - def check_url - return unless cask.url - check_download_url_format - end + def check_url + return unless cask.url + check_download_url_format + end - def check_download_url_format - odebug "Auditing URL format" - if bad_sourceforge_url? - add_warning "SourceForge URL format incorrect. See https://github.com/caskroom/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/url.md#sourceforgeosdn-urls" - elsif bad_osdn_url? - add_warning "OSDN URL format incorrect. See https://github.com/caskroom/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/url.md#sourceforgeosdn-urls" + def check_download_url_format + odebug "Auditing URL format" + if bad_sourceforge_url? + add_warning "SourceForge URL format incorrect. See https://github.com/caskroom/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/url.md#sourceforgeosdn-urls" + elsif bad_osdn_url? + add_warning "OSDN URL format incorrect. See https://github.com/caskroom/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/url.md#sourceforgeosdn-urls" + end end - end - def bad_url_format?(regex, valid_formats_array) - return false unless cask.url.to_s =~ regex - valid_formats_array.none? { |format| cask.url.to_s =~ format } - end + def bad_url_format?(regex, valid_formats_array) + return false unless cask.url.to_s =~ regex + valid_formats_array.none? { |format| cask.url.to_s =~ format } + end - def bad_sourceforge_url? - bad_url_format?(%r{sourceforge}, - [ - %r{\Ahttps://sourceforge\.net/projects/[^/]+/files/latest/download\Z}, - %r{\Ahttps://downloads\.sourceforge\.net/(?!(project|sourceforge)\/)}, - # special cases: cannot find canonical format URL - %r{\Ahttps?://brushviewer\.sourceforge\.net/brushviewql\.zip\Z}, - %r{\Ahttps?://doublecommand\.sourceforge\.net/files/}, - %r{\Ahttps?://excalibur\.sourceforge\.net/get\.php\?id=}, - ]) - end + def bad_sourceforge_url? + bad_url_format?(%r{sourceforge}, + [ + %r{\Ahttps://sourceforge\.net/projects/[^/]+/files/latest/download\Z}, + %r{\Ahttps://downloads\.sourceforge\.net/(?!(project|sourceforge)\/)}, + # special cases: cannot find canonical format URL + %r{\Ahttps?://brushviewer\.sourceforge\.net/brushviewql\.zip\Z}, + %r{\Ahttps?://doublecommand\.sourceforge\.net/files/}, + %r{\Ahttps?://excalibur\.sourceforge\.net/get\.php\?id=}, + ]) + end - def bad_osdn_url? - bad_url_format?(%r{osd}, [%r{\Ahttps?://([^/]+.)?dl\.osdn\.jp/}]) - end + def bad_osdn_url? + bad_url_format?(%r{osd}, [%r{\Ahttps?://([^/]+.)?dl\.osdn\.jp/}]) + end - def check_generic_artifacts - cask.artifacts[:artifact].each do |source, target_hash| - unless target_hash.is_a?(Hash) && target_hash[:target] - add_error "target required for generic artifact #{source}" - next + def check_generic_artifacts + cask.artifacts[:artifact].each do |source, target_hash| + unless target_hash.is_a?(Hash) && target_hash[:target] + add_error "target required for generic artifact #{source}" + next + end + add_error "target must be absolute path for generic artifact #{source}" unless Pathname.new(target_hash[:target]).absolute? end - add_error "target must be absolute path for generic artifact #{source}" unless Pathname.new(target_hash[:target]).absolute? end - end - def check_token_conflicts - return unless check_token_conflicts? - return unless core_formula_names.include?(cask.token) - add_warning "possible duplicate, cask token conflicts with Homebrew core formula: #{core_formula_url}" - end + def check_token_conflicts + return unless check_token_conflicts? + return unless core_formula_names.include?(cask.token) + add_warning "possible duplicate, cask token conflicts with Homebrew core formula: #{core_formula_url}" + end - def core_tap - @core_tap ||= CoreTap.instance - end + def core_tap + @core_tap ||= CoreTap.instance + end - def core_formula_names - core_tap.formula_names - end + def core_formula_names + core_tap.formula_names + end - def core_formula_url - "#{core_tap.default_remote}/blob/master/Formula/#{cask.token}.rb" - end + def core_formula_url + "#{core_tap.default_remote}/blob/master/Formula/#{cask.token}.rb" + end - def check_download - return unless download && cask.url - odebug "Auditing download" - downloaded_path = download.perform - Hbc::Verify.all(cask, downloaded_path) - rescue => e - add_error "download not possible: #{e.message}" + def check_download + return unless download && cask.url + odebug "Auditing download" + downloaded_path = download.perform + Verify.all(cask, downloaded_path) + rescue => e + add_error "download not possible: #{e.message}" + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/auditor.rb
@@ -1,10 +1,12 @@ -class Hbc::Auditor - def self.audit(cask, audit_download: false, check_token_conflicts: false) - download = audit_download && Hbc::Download.new(cask) - audit = Hbc::Audit.new(cask, download: download, - check_token_conflicts: check_token_conflicts) - audit.run! - puts audit.summary - audit.success? +module Hbc + class Auditor + def self.audit(cask, audit_download: false, check_token_conflicts: false) + download = audit_download && Download.new(cask) + audit = Audit.new(cask, download: download, + check_token_conflicts: check_token_conflicts) + audit.run! + puts audit.summary + audit.success? + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/cache.rb
@@ -1,34 +1,36 @@ -module Hbc::Cache - module_function +module Hbc + module Cache + module_function - def ensure_cache_exists - return if Hbc.cache.exist? + def ensure_cache_exists + return if Hbc.cache.exist? - odebug "Creating Cache at #{Hbc.cache}" - Hbc.cache.mkpath - end + odebug "Creating Cache at #{Hbc.cache}" + Hbc.cache.mkpath + end - def migrate_legacy_cache - return unless Hbc.legacy_cache.exist? + def migrate_legacy_cache + return unless Hbc.legacy_cache.exist? - ohai "Migrating cached files to #{Hbc.cache}..." - Hbc.legacy_cache.children.select(&:symlink?).each do |symlink| - file = symlink.readlink + ohai "Migrating cached files to #{Hbc.cache}..." + Hbc.legacy_cache.children.select(&:symlink?).each do |symlink| + file = symlink.readlink - new_name = file.basename - .sub(%r{\-((?:(\d|#{Hbc::DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x, - '--\1') + new_name = file.basename + .sub(%r{\-((?:(\d|#{DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x, + '--\1') - renamed_file = Hbc.cache.join(new_name) + renamed_file = Hbc.cache.join(new_name) - if file.exist? - puts "#{file} -> #{renamed_file}" - FileUtils.mv(file, renamed_file) + if file.exist? + puts "#{file} -> #{renamed_file}" + FileUtils.mv(file, renamed_file) + end + + FileUtils.rm(symlink) end - FileUtils.rm(symlink) + FileUtils.remove_entry_secure(Hbc.legacy_cache) end - - FileUtils.remove_entry_secure(Hbc.legacy_cache) end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/cask.rb
@@ -2,114 +2,116 @@ require "hbc/dsl" -class Hbc::Cask - extend Forwardable +module Hbc + class Cask + extend Forwardable - attr_reader :token, :sourcefile_path - def initialize(token, sourcefile_path: nil, dsl: nil, &block) - @token = token - @sourcefile_path = sourcefile_path - @dsl = dsl || Hbc::DSL.new(@token) - @dsl.instance_eval(&block) if block_given? - end - - Hbc::DSL::DSL_METHODS.each do |method_name| - define_method(method_name) { @dsl.send(method_name) } - end - - METADATA_SUBDIR = ".metadata".freeze + attr_reader :token, :sourcefile_path + def initialize(token, sourcefile_path: nil, dsl: nil, &block) + @token = token + @sourcefile_path = sourcefile_path + @dsl = dsl || DSL.new(@token) + @dsl.instance_eval(&block) if block_given? + end - def metadata_master_container_path - @metadata_master_container_path ||= caskroom_path.join(METADATA_SUBDIR) - end + DSL::DSL_METHODS.each do |method_name| + define_method(method_name) { @dsl.send(method_name) } + end - def metadata_versioned_container_path - cask_version = version ? version : :unknown - metadata_master_container_path.join(cask_version.to_s) - end + METADATA_SUBDIR = ".metadata".freeze - def metadata_path(timestamp = :latest, create = false) - return nil unless metadata_versioned_container_path.respond_to?(:join) - if create && timestamp == :latest - raise Hbc::CaskError, "Cannot create metadata path when timestamp is :latest" - end - path = if timestamp == :latest - Pathname.glob(metadata_versioned_container_path.join("*")).sort.last - elsif timestamp == :now - Hbc::Utils.nowstamp_metadata_path(metadata_versioned_container_path) - else - metadata_versioned_container_path.join(timestamp) - end - if create - odebug "Creating metadata directory #{path}" - FileUtils.mkdir_p path + def metadata_master_container_path + @metadata_master_container_path ||= caskroom_path.join(METADATA_SUBDIR) end - path - end - def metadata_subdir(leaf, timestamp = :latest, create = false) - if create && timestamp == :latest - raise Hbc::CaskError, "Cannot create metadata subdir when timestamp is :latest" + def metadata_versioned_container_path + cask_version = version ? version : :unknown + metadata_master_container_path.join(cask_version.to_s) end - unless leaf.respond_to?(:length) && !leaf.empty? - raise Hbc::CaskError, "Cannot create metadata subdir for empty leaf" + + def metadata_path(timestamp = :latest, create = false) + return nil unless metadata_versioned_container_path.respond_to?(:join) + if create && timestamp == :latest + raise CaskError, "Cannot create metadata path when timestamp is :latest" + end + path = if timestamp == :latest + Pathname.glob(metadata_versioned_container_path.join("*")).sort.last + elsif timestamp == :now + Utils.nowstamp_metadata_path(metadata_versioned_container_path) + else + metadata_versioned_container_path.join(timestamp) + end + if create + odebug "Creating metadata directory #{path}" + FileUtils.mkdir_p path + end + path end - parent = metadata_path(timestamp, create) - return nil unless parent.respond_to?(:join) - subdir = parent.join(leaf) - if create - odebug "Creating metadata subdirectory #{subdir}" - FileUtils.mkdir_p subdir + + def metadata_subdir(leaf, timestamp = :latest, create = false) + if create && timestamp == :latest + raise CaskError, "Cannot create metadata subdir when timestamp is :latest" + end + unless leaf.respond_to?(:length) && !leaf.empty? + raise CaskError, "Cannot create metadata subdir for empty leaf" + end + parent = metadata_path(timestamp, create) + return nil unless parent.respond_to?(:join) + subdir = parent.join(leaf) + if create + odebug "Creating metadata subdirectory #{subdir}" + FileUtils.mkdir_p subdir + end + subdir end - subdir - end - def timestamped_versions - Pathname.glob(metadata_master_container_path.join("*", "*")) - .map { |p| p.relative_path_from(metadata_master_container_path) } - .sort_by(&:basename) # sort by timestamp - .map(&:split) - end + def timestamped_versions + Pathname.glob(metadata_master_container_path.join("*", "*")) + .map { |p| p.relative_path_from(metadata_master_container_path) } + .sort_by(&:basename) # sort by timestamp + .map(&:split) + end - def versions - timestamped_versions.map(&:first) - .reverse - .uniq - .reverse - end + def versions + timestamped_versions.map(&:first) + .reverse + .uniq + .reverse + end - def installed? - !versions.empty? - end + def installed? + !versions.empty? + end - def to_s - @token - end + def to_s + @token + end - def dumpcask - return unless Hbc.respond_to?(:debug) - return unless Hbc.debug + def dumpcask + return unless Hbc.respond_to?(:debug) + return unless Hbc.debug - odebug "Cask instance dumps in YAML:" - odebug "Cask instance toplevel:", to_yaml - [ - :name, - :homepage, - :url, - :appcast, - :version, - :license, - :sha256, - :artifacts, - :caveats, - :depends_on, - :conflicts_with, - :container, - :gpg, - :accessibility_access, - :auto_updates, - ].each do |method| - odebug "Cask instance method '#{method}':", send(method).to_yaml + odebug "Cask instance dumps in YAML:" + odebug "Cask instance toplevel:", to_yaml + [ + :name, + :homepage, + :url, + :appcast, + :version, + :license, + :sha256, + :artifacts, + :caveats, + :depends_on, + :conflicts_with, + :container, + :gpg, + :accessibility_access, + :auto_updates, + ].each do |method| + odebug "Cask instance method '#{method}':", send(method).to_yaml + end end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/cask_dependencies.rb
@@ -1,33 +1,35 @@ require "hbc/topological_hash" -class Hbc::CaskDependencies - attr_reader :cask, :graph, :sorted +module Hbc + class CaskDependencies + attr_reader :cask, :graph, :sorted - def initialize(cask) - @cask = cask - @graph = graph_dependencies - @sorted = sort - end + def initialize(cask) + @cask = cask + @graph = graph_dependencies + @sorted = sort + end - def graph_dependencies - deps_in = ->(csk) { csk.depends_on ? csk.depends_on.cask || [] : [] } - walk = lambda { |acc, deps| - deps.each do |dep| - next if acc.key?(dep) - succs = deps_in.call Hbc.load(dep) - acc[dep] = succs - walk.call(acc, succs) - end - acc - } + def graph_dependencies + deps_in = ->(csk) { csk.depends_on ? csk.depends_on.cask || [] : [] } + walk = lambda { |acc, deps| + deps.each do |dep| + next if acc.key?(dep) + succs = deps_in.call Hbc.load(dep) + acc[dep] = succs + walk.call(acc, succs) + end + acc + } - graphed = walk.call({}, @cask.depends_on.cask) - Hbc::TopologicalHash[graphed] - end + graphed = walk.call({}, @cask.depends_on.cask) + TopologicalHash[graphed] + end - def sort - @graph.tsort - rescue TSort::Cyclic - raise Hbc::CaskCyclicCaskDependencyError, @cask.token + def sort + @graph.tsort + rescue TSort::Cyclic + raise CaskCyclicCaskDependencyError, @cask.token + end end end
true
Other
Homebrew
brew
b86c8efb79b3ed835d552c4d7416640ef10caf21.json
Cask: Use nested classes and modules.
Library/Homebrew/cask/lib/hbc/caskroom.rb
@@ -1,41 +1,43 @@ -module Hbc::Caskroom - module_function +module Hbc + module Caskroom + module_function - def migrate_caskroom_from_repo_to_prefix - repo_caskroom = Hbc.homebrew_repository.join("Caskroom") - return if Hbc.caskroom.exist? - return unless repo_caskroom.directory? + def migrate_caskroom_from_repo_to_prefix + repo_caskroom = Hbc.homebrew_repository.join("Caskroom") + return if Hbc.caskroom.exist? + return unless repo_caskroom.directory? - ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX" + ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX" - if Hbc.caskroom.parent.writable? - FileUtils.mv repo_caskroom, Hbc.caskroom - else - opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom." - system "/usr/bin/sudo", "--", "/bin/mv", "--", repo_caskroom.to_s, Hbc.caskroom.parent.to_s + if Hbc.caskroom.parent.writable? + FileUtils.mv repo_caskroom, Hbc.caskroom + else + opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom." + system "/usr/bin/sudo", "--", "/bin/mv", "--", repo_caskroom.to_s, Hbc.caskroom.parent.to_s + end end - end - def ensure_caskroom_exists - return if Hbc.caskroom.exist? + def ensure_caskroom_exists + return if Hbc.caskroom.exist? - ohai "Creating Caskroom at #{Hbc.caskroom}" - if Hbc.caskroom.parent.writable? - Hbc.caskroom.mkpath - else - ohai "We'll set permissions properly so we won't need sudo in the future" - toplevel_dir = Hbc.caskroom - toplevel_dir = toplevel_dir.parent until toplevel_dir.parent.root? - unless toplevel_dir.directory? - # If a toplevel dir such as '/opt' must be created, enforce standard permissions. + ohai "Creating Caskroom at #{Hbc.caskroom}" + if Hbc.caskroom.parent.writable? + Hbc.caskroom.mkpath + else + ohai "We'll set permissions properly so we won't need sudo in the future" + toplevel_dir = Hbc.caskroom + toplevel_dir = toplevel_dir.parent until toplevel_dir.parent.root? + unless toplevel_dir.directory? + # If a toplevel dir such as '/opt' must be created, enforce standard permissions. + # sudo in system is rude. + system "/usr/bin/sudo", "--", "/bin/mkdir", "--", toplevel_dir + system "/usr/bin/sudo", "--", "/bin/chmod", "--", "0775", toplevel_dir + end # sudo in system is rude. - system "/usr/bin/sudo", "--", "/bin/mkdir", "--", toplevel_dir - system "/usr/bin/sudo", "--", "/bin/chmod", "--", "0775", toplevel_dir - end - # sudo in system is rude. - system "/usr/bin/sudo", "--", "/bin/mkdir", "-p", "--", Hbc.caskroom - unless Hbc.caskroom.parent == toplevel_dir - system "/usr/bin/sudo", "--", "/usr/sbin/chown", "-R", "--", "#{Hbc::Utils.current_user}:staff", Hbc.caskroom.parent.to_s + system "/usr/bin/sudo", "--", "/bin/mkdir", "-p", "--", Hbc.caskroom + unless Hbc.caskroom.parent == toplevel_dir + system "/usr/bin/sudo", "--", "/usr/sbin/chown", "-R", "--", "#{Utils.current_user}:staff", Hbc.caskroom.parent.to_s + end end end end
true