Skip to content

Commit

Permalink
Better gem outdated list grouped by groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfox1985 committed Aug 19, 2016
1 parent 54ff7a4 commit db6fa8f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
69 changes: 43 additions & 26 deletions lib/bundler/cli/outdated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def run
end

Bundler.ui.info ""
gems_by_groups = {}

out_count = 0
# Loop through the current specs
gemfile_specs, dependency_specs = current_specs.partition {|spec| current_dependencies.key? spec.name }
[gemfile_specs.sort_by(&:name), dependency_specs.sort_by(&:name)].flatten.each do |current_spec|
Expand Down Expand Up @@ -67,47 +67,64 @@ def run
gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
git_outdated = current_spec.git_version != active_spec.git_version
if gem_outdated || git_outdated
unless options[:parseable]
if out_count == 0
if options["pre"]
Bundler.ui.info "Outdated gems included in the bundle (including pre-releases):"
else
Bundler.ui.info "Outdated gems included in the bundle:"
end
end
end

spec_version = "#{active_spec.version}#{active_spec.git_version}"
current_version = "#{current_spec.version}#{current_spec.git_version}"
dependency_version = %(, requested #{dependency.requirement}) if dependency && dependency.specific?

groups = nil
if dependency && !options[:parseable]
groups = dependency.groups.join(", ")
pl = (dependency.groups.length > 1) ? "s" : ""
groups = " in group#{pl} \"#{groups}\""
end

spec_outdated_info = "#{active_spec.name} (newest #{spec_version}, installed #{current_version}#{dependency_version})"
if options[:parseable]
Bundler.ui.info spec_outdated_info.to_s.rstrip
else
Bundler.ui.info " * #{spec_outdated_info}#{groups}".rstrip
end

out_count += 1
gems_by_groups[groups] ||= []
gems_by_groups[groups] << { :active_spec => active_spec,
:current_spec => current_spec,
:dependency => dependency }
end

Bundler.ui.debug "from #{active_spec.loaded_from}"
end

if out_count.zero?
if gems_by_groups.empty?
Bundler.ui.info "Bundle up to date!\n" unless options[:parseable]
else
unless options[:parseable]
if options["pre"]
Bundler.ui.info "Outdated gems included in the bundle (including pre-releases):"
else
Bundler.ui.info "Outdated gems included in the bundle:"
end
end

gems_by_groups.each do |groups, gems|
unless options[:parseable]
if groups
Bundler.ui.info "===== Group #{groups} ====="
else
Bundler.ui.info "===== Without group ====="
end
end

gems.each do |gem|
print_gem(gem[:current_spec], gem[:active_spec], gem[:dependency])
end
end

exit 1
end
end

private

def print_gem(current_spec, active_spec, dependency)
spec_version = "#{active_spec.version}#{active_spec.git_version}"
current_version = "#{current_spec.version}#{current_spec.git_version}"
dependency_version = %(, requested #{dependency.requirement}) if dependency && dependency.specific?

spec_outdated_info = "#{active_spec.name} (newest #{spec_version}, installed #{current_version}#{dependency_version})"
if options[:parseable]
Bundler.ui.info spec_outdated_info.to_s.rstrip
else
Bundler.ui.info " * #{spec_outdated_info}".rstrip
end
end

def check_for_deployment_mode
if Bundler.settings[:frozen]
error_message = "You are trying to check outdated gems in deployment mode. " \
Expand Down
3 changes: 2 additions & 1 deletion spec/commands/outdated_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
update_repo2 { build_gem "activesupport", "3.0" }

bundle "outdated --verbose"
expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5) in groups \"development, test\"")
expect(out).to include("===== Group development, test =====")
expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)")
end
end

Expand Down

0 comments on commit db6fa8f

Please sign in to comment.