diff options
| author | Markus Reiter | 2016-10-02 20:39:43 +0200 | 
|---|---|---|
| committer | Markus Reiter | 2016-10-15 17:13:38 +0200 | 
| commit | 198bf4d3bdeaf3047f9af80788ea18cd192541af (patch) | |
| tree | 613f8ec02a60b15ff12bb981d75759d54dbbee3c /Library | |
| parent | 429327cac8b75118087400fc9b5ffed4c4ce83ec (diff) | |
| download | brew-198bf4d3bdeaf3047f9af80788ea18cd192541af.tar.bz2 | |
Convert `puts_columns` to `puts Formatter.columns`.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/install.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/list.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/search.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/commands.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/install.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/list.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/search.rb | 9 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/update-report.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/uses.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/compat/utils.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_utils.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 1 | ||||
| -rw-r--r-- | Library/Homebrew/utils/formatter.rb | 1 | ||||
| -rw-r--r-- | Library/Homebrew/utils/formatter/columns.rb (renamed from Library/Homebrew/utils/puts_columns.rb) | 19 | 
14 files changed, 40 insertions, 27 deletions
| diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb index 1292ad076..3e9ce4e4f 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/install.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb @@ -42,12 +42,14 @@ module Hbc        def self.warn_unavailable_with_suggestion(cask_token, e)          exact_match, partial_matches = Search.search(cask_token) +        error_message = e.message          if exact_match -          onoe e.message.concat(". Did you mean:\n#{exact_match}") +          error_message.concat(". Did you mean:\n#{exact_match}")          elsif !partial_matches.empty? -          onoe e.message.concat(". Did you mean one of:") -          $stderr.puts_columns(partial_matches.take(20)) +          error_message.concat(". Did you mean one of:\n") +                       .concat(Formatter.columns(partial_matches.take(20)))          end +        onoe error_message        end        def self.help diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 3a993f8e6..330c81b90 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -68,7 +68,7 @@ module Hbc          elsif @options[:versions]            puts installed_casks.map(&method(:format_versioned))          else -          puts_columns installed_casks.map(&:to_s) +          puts Formatter.columns(installed_casks.map(&:to_s))          end          installed_casks.empty? ? nil : true diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index b671ea862..147e6d194 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -47,7 +47,7 @@ module Hbc            else              ohai "Partial matches"            end -          puts_columns partial_matches +          puts Formatter.columns(partial_matches)          end        end diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb index f6445d560..addccd609 100644 --- a/Library/Homebrew/cmd/commands.rb +++ b/Library/Homebrew/cmd/commands.rb @@ -12,22 +12,22 @@ module Homebrew        cmds = internal_commands + external_commands        cmds += internal_developer_commands        cmds += HOMEBREW_INTERNAL_COMMAND_ALIASES.keys if ARGV.include? "--include-aliases" -      puts_columns cmds.sort +      puts Formatter.columns(cmds.sort)      else        # Find commands in Homebrew/cmd        puts "Built-in commands" -      puts_columns internal_commands +      puts Formatter.columns(internal_commands)        # Find commands in Homebrew/dev-cmd        puts        puts "Built-in developer commands" -      puts_columns internal_developer_commands +      puts Formatter.columns(internal_developer_commands)        # Find commands in the path        unless (exts = external_commands).empty?          puts          puts "External commands" -        puts_columns exts +        puts Formatter.columns(exts)        end      end    end diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 209fe8bad..2c027a52e 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -183,7 +183,7 @@ module Homebrew            puts "To install it, run:\n  brew install #{formulae_search_results.first}"          else            puts "These similarly named formulae were found:" -          puts_columns(formulae_search_results) +          puts Formatter.columns(formulae_search_results)            puts "To install one of them, run (for example):\n  brew install #{formulae_search_results.first}"          end @@ -198,7 +198,7 @@ module Homebrew            puts "To install it, run:\n  brew install #{taps_search_results.first}"          else            puts "These formulae were found in taps:" -          puts_columns(taps_search_results) +          puts Formatter.columns(taps_search_results)            puts "To install one of them, run (for example):\n  brew install #{taps_search_results.first}"          end        end diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 93c2545ad..3496580f4 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -49,7 +49,7 @@ module Homebrew            end          end          return if full_names.empty? -        puts_columns full_names +        puts Formatter.columns(full_names)        else          ENV["CLICOLOR"] = nil          exec "ls", *ARGV.options_only << HOMEBREW_CELLAR diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index f0a276929..d69164eb9 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -27,7 +27,7 @@ module Homebrew    def search      if ARGV.empty? -      puts_columns Formula.full_names +      puts Formatter.columns(Formula.full_names)      elsif ARGV.include? "--macports"        exec_browser "https://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"      elsif ARGV.include? "--fink" @@ -54,14 +54,15 @@ module Homebrew          result = search_tap(user, repo, name)        end -      puts_columns Array(result) +      results = Array(result) +      puts Formatter.columns(results) unless results.empty?      else        query = ARGV.first        regex = query_regexp(query)        local_results = search_formulae(regex) -      puts_columns(local_results) unless local_results.empty? +      puts Formatter.columns(local_results) unless local_results.empty?        tap_results = search_taps(regex) -      puts_columns(tap_results) unless tap_results.empty? +      puts Formatter.columns(tap_results) unless tap_results.empty?        if $stdout.tty?          count = local_results.length + tap_results.length diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 629ce1f3f..72dcc293d 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -553,7 +553,7 @@ class ReporterHub      return if formulae.empty?      # Dump formula list.      ohai title -    puts_columns(formulae) +    puts Formatter.columns(formulae)    end    def installed?(formula) diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 66088e217..fb11a31a7 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -94,6 +94,6 @@ module Homebrew      end      return if uses.empty? -    puts_columns uses.map(&:full_name) +    puts Formatter.columns(uses.map(&:full_name))    end  end diff --git a/Library/Homebrew/compat/utils.rb b/Library/Homebrew/compat/utils.rb index 7b529f04e..ed6063472 100644 --- a/Library/Homebrew/compat/utils.rb +++ b/Library/Homebrew/compat/utils.rb @@ -16,3 +16,8 @@ module Tty      reset.bold    end  end + +def puts_columns(items) +  odeprecated "puts_columns", "puts Formatter.columns" +  puts Formatter.columns(items) +end diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb index c97d70285..11332e450 100644 --- a/Library/Homebrew/test/test_utils.rb +++ b/Library/Homebrew/test/test_utils.rb @@ -111,7 +111,7 @@ class UtilTests < Homebrew::TestCase    def test_put_columns_empty      out, err = capture_io do -      puts_columns [] +      puts Formatter.columns([])      end      assert_equal out, "\n" diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index e31339e16..fce03f888 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -11,7 +11,6 @@ require "utils/hash"  require "utils/inreplace"  require "utils/json"  require "utils/popen" -require "utils/puts_columns"  require "utils/tty"  def ohai(title, *sput) diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index cb4f041f4..3759e2b4f 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -1,3 +1,4 @@ +require "utils/formatter/columns"  require "utils/tty"  module Formatter diff --git a/Library/Homebrew/utils/puts_columns.rb b/Library/Homebrew/utils/formatter/columns.rb index 2810918c6..6488ef35f 100644 --- a/Library/Homebrew/utils/puts_columns.rb +++ b/Library/Homebrew/utils/formatter/columns.rb @@ -1,19 +1,20 @@  require "utils/tty" -module Kernel -  def puts_columns(*objects, gap_size: 2) -    objects.flatten! +module Formatter +  module_function + +  def columns(*objects, gap_size: 2) +    objects = objects.flatten.map(&:to_s)      fallback = proc do -      puts(*objects) -      return +      return objects.join("\n").concat("\n")      end      fallback.call if objects.empty?      fallback.call if respond_to?(:tty?) ? !tty? : !$stdout.tty?      console_width = Tty.width -    object_lengths = objects.map { |obj| Tty.strip_ansi(obj.to_s).length } +    object_lengths = objects.map { |obj| Tty.strip_ansi(obj).length }      cols = (console_width + gap_size) / (object_lengths.max + gap_size)      fallback.call if cols < 2 @@ -25,6 +26,8 @@ module Kernel      gap_string = "".rjust(gap_size) +    output = "" +      rows.times do |row_index|        item_indices_for_row = row_index.step(objects.size - 1, rows).to_a @@ -35,7 +38,9 @@ module Kernel        # don't add trailing whitespace to last column        last = objects.values_at(item_indices_for_row.last) -      puts (first_n + last).join(gap_string) +      output.concat((first_n + last).join(gap_string)).concat("\n")      end + +    output    end  end | 
