diff options
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/brew.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/moved.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb | 15 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/checkable.rb | 10 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/doctor.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/info.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/installer.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/utils.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/doctor.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/info.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/descriptions.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/dev-cmd/bottle.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/exceptions.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/formula_installer.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/migrator.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 21 | ||||
| -rw-r--r-- | Library/Homebrew/utils/formatter.rb | 52 | ||||
| -rw-r--r-- | Library/Homebrew/utils/github.rb | 6 |
18 files changed, 109 insertions, 55 deletions
diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 4ea830806..c4a34d298 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -147,8 +147,8 @@ rescue Exception => e 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 diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb index ff6e5f273..22124005c 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb @@ -79,12 +79,10 @@ module Hbc 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 diff --git a/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb b/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb index 3ab45cccc..46dd42322 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb @@ -57,12 +57,17 @@ module Hbc 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 diff --git a/Library/Homebrew/cask/lib/hbc/checkable.rb b/Library/Homebrew/cask/lib/hbc/checkable.rb index 42c47ea78..03f052629 100644 --- a/Library/Homebrew/cask/lib/hbc/checkable.rb +++ b/Library/Homebrew/cask/lib/hbc/checkable.rb @@ -28,11 +28,11 @@ module Hbc 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 @@ -40,11 +40,11 @@ module Hbc 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") diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb index 34f000b29..e36999200 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb @@ -122,11 +122,11 @@ module Hbc 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) diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index e2f360296..0957ba4fd 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -18,9 +18,9 @@ module Hbc 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 @@ module Hbc 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 @@ module Hbc 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) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 1002be460..4d29acb75 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -87,7 +87,7 @@ module Hbc 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 diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index c6a970fca..d42d78ef7 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -32,7 +32,7 @@ end 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 @@ module Hbc 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 diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index e6b5fcba0..0fcd3a74d 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -42,9 +42,9 @@ module Homebrew 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 diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 9721585cf..2cfb89ea5 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -117,7 +117,7 @@ module Homebrew 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 @@ module Homebrew end end - puts "From: #{Tty.underline}#{github_info(f)}#{Tty.reset}" + puts "From: #{Formatter.url(github_info(f))}" unless f.deps.empty? ohai "Dependencies" diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb index 63f2dd648..cc690c050 100644 --- a/Library/Homebrew/descriptions.rb +++ b/Library/Homebrew/descriptions.rb @@ -119,7 +119,7 @@ class 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 diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index e5a6f4ebd..8c6d3e564 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -54,7 +54,7 @@ module Homebrew return if @put_filenames.include? filename - puts "#{Tty.red}#{filename}#{Tty.reset}" + puts Formatter.error(filename.to_s) @put_filenames << filename end diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 9810d8bfa..601bde528 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -318,7 +318,7 @@ class BuildError < RuntimeError 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" diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 652f87ae3..09c11318e 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -214,7 +214,7 @@ class FormulaInstaller 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 @@ class FormulaInstaller 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 @@ class FormulaInstaller 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 diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 7b53f2fd1..fe480cd3b 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -153,7 +153,7 @@ class Migrator 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,7 +200,7 @@ class Migrator 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 @@ -208,7 +208,7 @@ class Migrator 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. diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 5c0aa601d..8d91c15c0 100644 --- a/Library/Homebrew/utils.rb +++ b/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,7 +15,7 @@ require "utils/tty" 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 @@ -22,16 +23,16 @@ 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,9 +98,9 @@ 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 @@ -107,9 +108,9 @@ 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 diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb new file mode 100644 index 000000000..cb4f041f4 --- /dev/null +++ b/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 diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index e71039e12..1443a9336 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -14,7 +14,7 @@ module GitHub 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,7 +30,7 @@ module GitHub 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 @@ -38,7 +38,7 @@ module GitHub 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 |
