Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge #4474
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people committed Oct 14, 2019
2 parents fe5d24b + 76b1d89 commit c9d1635
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 131 deletions.
114 changes: 75 additions & 39 deletions lib/bundler/cli/outdated.rb
Expand Up @@ -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
Expand All @@ -12,7 +12,7 @@ def initialize(options, gems)

@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)
Expand Down Expand Up @@ -87,32 +87,38 @@ def run
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
Expand All @@ -125,22 +131,6 @@ def groups_text(group_text, groups)
"#{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|
Expand All @@ -167,12 +157,6 @@ def retrieve_active_spec(definition, current_spec)
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(
Expand All @@ -184,6 +168,19 @@ def print_gems(gems_list)
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
Expand All @@ -207,6 +204,16 @@ def print_gem(current_spec, active_spec, dependency, groups)
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]
Expand Down Expand Up @@ -253,5 +260,34 @@ def get_version_semver_portion_value(spec, version_portion_index)
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

0 comments on commit c9d1635

Please sign in to comment.