diff options
author | Todd Lynam <TLynam@gmail.com> | 2016-10-27 21:12:38 -0700 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-10-12 16:46:28 +0200 |
commit | dba2a0b62a86dc3ac5bb358c525777208199f330 (patch) | |
tree | 5033dc8dc752079b9418e944e5ad853c9a556230 /lib | |
parent | 746e48797292c6eb70eb398ee6d4ed4afd683c7c (diff) | |
download | bundler-dba2a0b62a86dc3ac5bb358c525777208199f330.tar.gz |
Improve readability of outdated
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli.rb | 1 | ||||
-rw-r--r-- | lib/bundler/cli/outdated.rb | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 0083f7e7de..c3dc691c11 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -407,6 +407,7 @@ module Bundler "Use minimal formatting for more parseable output" method_option "only-explicit", :type => :boolean, :banner => "Only list gems specified in your Gemfile, not their dependencies" + method_option "pretty", :type => :boolean, :banner => "Use pretty formatting" def outdated(*gems) require_relative "cli/outdated" Outdated.new(options, gems).run diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index ae40d05021..b5b3356f86 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -111,6 +111,21 @@ module Bundler print_gems(gems) end + elsif options[:pretty] + header = ["Gem Name", "Installed", "New", "Requested", "Groups"] + header << "Load Path" if options[:verbose] + + outdated_gems_list.map! do |gem| + current_version = "#{gem[:current_spec].version}#{gem[:current_spec].git_version}" + spec_version = "#{gem[:active_spec].version}#{gem[:active_spec].git_version}" + dependency = gem[:dependency].requirement if gem[:dependency] && gem[:dependency].specific? + + ret_val = [gem[:active_spec].name, current_version, spec_version, dependency.to_s, gem[:groups].to_s] + ret_val << gem[:active_spec].loaded_from if options[:verbose] + ret_val + end + + print_indented header, *outdated_gems_list else print_gems(outdated_gems_list) end @@ -253,5 +268,23 @@ module Bundler version_section = spec.version.segments[version_portion_index, 1] version_section.to_a[0].to_i end + + def print_indented(*data) + columns = data.first.size + + column_sizes = Array.new(columns) do |index| + data.max_by {|row| row[index].to_s.length }[index].length + end + + data.sort_by! {|row| row[0] } + + data.each do |row| + row = row.each_with_index.map do |element, index| + element.to_s.ljust(column_sizes[index]) + end + + Bundler.ui.info row.join(" ") + "\n" + end + end end end |