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

Improve readability of outdated #4474

Merged
22 commits merged into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
746e487
Reword one spec
deivid-rodriguez Sep 30, 2019
dba2a0b
Improve readability of outdated
tlynam Oct 28, 2016
c004288
Extract table header to a method
deivid-rodriguez Sep 30, 2019
cf0ac92
Make hash alignment style more diff-friendly
deivid-rodriguez Sep 30, 2019
3742b33
Rename outdated_gems_list
deivid-rodriguez Sep 30, 2019
f6ef150
Add a bit more space between columns
deivid-rodriguez Sep 30, 2019
3ed6cf8
Change "Gem Name" header to just "Gem"
deivid-rodriguez Sep 27, 2019
17e71ea
Change "New" header to "Latest"
deivid-rodriguez Sep 27, 2019
78ae7d9
Remove outdated header
deivid-rodriguez Sep 27, 2019
43b4c56
Remove unnecessary expectations
deivid-rodriguez Oct 1, 2019
a4d2ff4
Tighten some expectations
deivid-rodriguez Oct 1, 2019
fb72186
Change "Load Path" header to just "Path"
deivid-rodriguez Oct 1, 2019
5ab4db1
Change "Installed" column to "Locked"
deivid-rodriguez Oct 1, 2019
0c9aeb9
Consistenly pass strings to method that prints a table
deivid-rodriguez Oct 1, 2019
95e9bd9
Move row justification logic to a method
deivid-rodriguez Oct 1, 2019
37ae646
Strip row trailing spaces
deivid-rodriguez Oct 1, 2019
eb47767
Remove --pretty option and make it the default
deivid-rodriguez Oct 1, 2019
a65304f
Don't include table header when ordering
deivid-rodriguez Oct 1, 2019
f5ddf68
Inline one method
deivid-rodriguez Oct 1, 2019
73ff5d5
Normalize `bundle outdated --verbose` option handling
deivid-rodriguez Oct 1, 2019
a7cec29
Split --verbose option to a separate spec
deivid-rodriguez Oct 1, 2019
76b1d89
Rename "Locked" to "Current"
deivid-rodriguez Oct 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 75 additions & 39 deletions lib/bundler/cli/outdated.rb
Original file line number Diff line number Diff line change
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
Loading