summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-10-14 20:23:56 +0000
committerBundlerbot <bot@bundler.io>2019-10-14 20:23:56 +0000
commitc9d16351b4e2a8a41ce9e3a812b7612970b25a78 (patch)
tree3eac13e7adcb63bab8b17120341c75263dcfc861 /lib
parentfe5d24b5dc6614c0edfee8407acba14aa610ac72 (diff)
parent76b1d8916a0d1204e263a874b4babb757a6de2a4 (diff)
downloadbundler-c9d16351b4e2a8a41ce9e3a812b7612970b25a78.tar.gz
Merge #4474
4474: Improve readability of outdated r=deivid-rodriguez a=tlynam Haven't fixed tests since wanted buy-in. Before: ``` Outdated gems included in the bundle: * active_model_serializers (newest 0.9.5, installed 0.8.3, requested ~> 0.8.0) in group "default" * activerecord-import (newest 0.13.0, installed 0.10.0) in group "default" * addressable (newest 2.4.0, installed 2.3.5, requested = 2.3.5) in group "default" * airbrake (newest 5.2.3, installed 5.1.0) in group "default" * bootstrap-sass (newest 3.3.6, installed 3.3.5.1) in group "default" * capistrano (newest 3.5.0, installed 3.4.0, requested ~> 3.4) in group "development" * capistrano-rails (newest 1.1.6, installed 1.1.3, requested ~> 1.1.1) in group "development" ``` After: ``` --pretty Outdated gems included in the bundle: Gem Name New Installed Requested Groups airbrake 5.3.0 5.0.3 default better_errors 2.1.1 1.0.1 ~> 1.0.1 development bootstrap-sass 3.3.6 3.3.0.1 ~> 3.3.0.1 default factory_girl_rails 4.7.0 4.4.1 test, development --pretty --verbose Outdated gems included in the bundle: Gem Name New Installed Requested Groups Load Path airbrake 5.3.0 5.0.3 default /Users/todd/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/specifications/airbrake-5.3.0.gemspec better_errors 2.1.1 1.0.1 ~> 1.0.1 development /Users/todd/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/specifications/better_errors-2.1.1.gemspec bootstrap-sass 3.3.6 3.3.0.1 ~> 3.3.0.1 default /Users/todd/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/specifications/bootstrap-sass-3.3.6.gemspec factory_girl 4.7.0 4.4.0 /Users/todd/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/specifications/factory_girl-4.7.0.gemspec factory_girl_rails 4.7.0 4.4.1 test, development /Users/todd/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/specifications/factory_girl_rails-4.7.0.gemspec ``` Co-authored-by: Todd Lynam <tlynam@gmail.com> Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/cli/outdated.rb114
1 files changed, 75 insertions, 39 deletions
diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb
index ae40d05021..3d4922f8b5 100644
--- a/lib/bundler/cli/outdated.rb
+++ b/lib/bundler/cli/outdated.rb
@@ -3,7 +3,7 @@
module Bundler
class CLI::Outdated
attr_reader :options, :gems, :options_include_groups, :filter_options_patch, :sources, :strict
- attr_accessor :outdated_gems_list
+ attr_accessor :outdated_gems
def initialize(options, gems)
@options = options
@@ -12,7 +12,7 @@ module Bundler
@filter_options_patch = options.keys & %w[filter-major filter-minor filter-patch]
- @outdated_gems_list = []
+ @outdated_gems = []
@options_include_groups = [:group, :groups].any? do |v|
options.keys.include?(v.to_s)
@@ -87,32 +87,38 @@ module Bundler
groups = dependency.groups.join(", ")
end
- outdated_gems_list << { :active_spec => active_spec,
- :current_spec => current_spec,
- :dependency => dependency,
- :groups => groups }
+ outdated_gems << {
+ :active_spec => active_spec,
+ :current_spec => current_spec,
+ :dependency => dependency,
+ :groups => groups,
+ }
end
- if outdated_gems_list.empty?
- display_nothing_outdated_message
- else
+ if outdated_gems.empty?
unless options[:parseable]
- Bundler.ui.info(header_outdated_message)
+ Bundler.ui.info(nothing_outdated_message)
end
-
+ else
if options_include_groups
- outdated_gems_list.group_by {|g| g[:groups] }.sort.each do |groups, gems|
+ relevant_outdated_gems = outdated_gems.group_by {|g| g[:groups] }.sort.flat_map do |groups, gems|
contains_group = groups.split(", ").include?(options[:group])
next unless options[:groups] || contains_group
- unless options[:parseable]
- Bundler.ui.info(header_group_message(groups))
- end
+ gems
+ end.compact
- print_gems(gems)
+ if options[:parseable]
+ relevant_outdated_gems.each do |gems|
+ print_gems(gems)
+ end
+ else
+ print_gems_table(relevant_outdated_gems)
end
+ elsif options[:parseable]
+ print_gems(outdated_gems)
else
- print_gems(outdated_gems_list)
+ print_gems_table(outdated_gems)
end
exit 1
@@ -125,22 +131,6 @@ module Bundler
"#{group_text}#{groups.split(",").size > 1 ? "s" : ""} \"#{groups}\""
end
- def header_outdated_message
- if options[:pre]
- "Outdated gems included in the bundle (including pre-releases):"
- else
- "Outdated gems included in the bundle:"
- end
- end
-
- def header_group_message(groups)
- if groups.empty?
- "===== Without group ====="
- else
- "===== #{groups_text("Group", groups)} ====="
- end
- end
-
def nothing_outdated_message
if filter_options_patch.any?
display = filter_options_patch.map do |o|
@@ -167,12 +157,6 @@ module Bundler
active_spec
end
- def display_nothing_outdated_message
- unless options[:parseable]
- Bundler.ui.info(nothing_outdated_message)
- end
- end
-
def print_gems(gems_list)
gems_list.each do |gem|
print_gem(
@@ -184,6 +168,19 @@ module Bundler
end
end
+ def print_gems_table(gems_list)
+ data = gems_list.map do |gem|
+ gem_column_for(
+ gem[:current_spec],
+ gem[:active_spec],
+ gem[:dependency],
+ gem[:groups],
+ )
+ end
+
+ print_indented([table_header] + data)
+ end
+
def print_gem(current_spec, active_spec, dependency, groups)
spec_version = "#{active_spec.version}#{active_spec.git_version}"
spec_version += " (from #{active_spec.loaded_from})" if Bundler.ui.debug? && active_spec.loaded_from
@@ -207,6 +204,16 @@ module Bundler
Bundler.ui.info output_message.rstrip
end
+ def gem_column_for(current_spec, active_spec, dependency, groups)
+ current_version = "#{current_spec.version}#{current_spec.git_version}"
+ spec_version = "#{active_spec.version}#{active_spec.git_version}"
+ dependency = dependency.requirement if dependency
+
+ ret_val = [active_spec.name, current_version, spec_version, dependency.to_s, groups.to_s]
+ ret_val << active_spec.loaded_from.to_s if Bundler.ui.debug?
+ ret_val
+ end
+
def check_for_deployment_mode!
return unless Bundler.frozen_bundle?
suggested_command = if Bundler.settings.locations("frozen")[:global]
@@ -253,5 +260,34 @@ module Bundler
version_section = spec.version.segments[version_portion_index, 1]
version_section.to_a[0].to_i
end
+
+ def print_indented(matrix)
+ header = matrix[0]
+ data = matrix[1..-1]
+
+ column_sizes = Array.new(header.size) do |index|
+ matrix.max_by {|row| row[index].length }[index].length
+ end
+
+ Bundler.ui.info justify(header, column_sizes)
+
+ data.sort_by! {|row| row[0] }
+
+ data.each do |row|
+ Bundler.ui.info justify(row, column_sizes)
+ end
+ end
+
+ def table_header
+ header = ["Gem", "Current", "Latest", "Requested", "Groups"]
+ header << "Path" if Bundler.ui.debug?
+ header
+ end
+
+ def justify(row, sizes)
+ row.each_with_index.map do |element, index|
+ element.ljust(sizes[index])
+ end.join(" ").strip + "\n"
+ end
end
end