diff options
author | Guillermo Guerrero <wolf.fox1985@gmail.com> | 2016-08-08 12:53:33 +0200 |
---|---|---|
committer | Guillermo Guerrero <wolf.fox1985@gmail.com> | 2016-10-06 02:58:26 +0200 |
commit | 3725a230fa5b4202ee0b026707400d3a998b252e (patch) | |
tree | 3ef1666bbca8c519b0e41f141823b688ee207e5e | |
parent | b430c478a25519348106cc94229b4248e4f8974e (diff) | |
download | bundler-3725a230fa5b4202ee0b026707400d3a998b252e.tar.gz |
Better gem outdated list grouped by groups.
Restore default outdated.
Added command in cli:
- bundle outdated --groups
Added --group option.
Groups with alphabetical order.
Added test. Reverted.
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/outdated.rb | 99 | ||||
-rw-r--r-- | spec/commands/outdated_spec.rb | 114 |
3 files changed, 187 insertions, 28 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index e27f498f94..f92ecb1c33 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -269,6 +269,8 @@ module Bundler versions of the given gems. Prerelease gems are ignored by default. If your gems are up to date, Bundler will exit with a status of 0. Otherwise, it will exit 1. D + method_option "group", :aliases => "--group", :type => :string, :banner => "List gems from a specific group" + method_option "groups", :aliases => "--groups", :type => :boolean, :banner => "List gems organized by groups" method_option "local", :type => :boolean, :banner => "Do not attempt to fetch gems remotely and use the gem cache instead" method_option "pre", :type => :boolean, :banner => "Check for newer pre-release gems" diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index de71075522..5729c07ffe 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -4,6 +4,7 @@ require "bundler/cli/common" module Bundler class CLI::Outdated attr_reader :options, :gems + def initialize(options, gems) @options = options @gems = gems @@ -30,7 +31,7 @@ module Bundler Bundler.definition(:gems => gems, :sources => sources) end - definition_resolution = proc { options["local"] ? definition.resolve_with_cache! : definition.resolve_remotely! } + definition_resolution = proc { options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely! } if options[:parseable] Bundler.ui.silence(&definition_resolution) else @@ -38,8 +39,9 @@ module Bundler end Bundler.ui.info "" + outdated_gems_by_groups = {} + outdated_gems_list = [] - 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| @@ -47,7 +49,7 @@ module Bundler dependency = current_dependencies[current_spec.name] - if options["strict"] + if options[:strict] active_spec = definition.specs.detect {|spec| spec.name == current_spec.name && spec.platform == current_spec.platform } else active_specs = definition.index[current_spec.name].select {|spec| spec.platform == current_spec.platform }.sort_by(&:version) @@ -67,47 +69,89 @@ module Bundler 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 + outdated_gems_list << { :active_spec => active_spec, + :current_spec => current_spec, + :dependency => dependency, + :groups => groups } - out_count += 1 + outdated_gems_by_groups[groups] ||= [] + outdated_gems_by_groups[groups] << { :active_spec => active_spec, + :current_spec => current_spec, + :dependency => dependency, + :groups => groups } end + Bundler.ui.debug "from #{active_spec.loaded_from}" end - if out_count.zero? + if outdated_gems_list.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 + + options_include_groups = [:group, :groups].select {|v| options.keys.include?(v.to_s) } + if options_include_groups.any? + ordered_groups = outdated_gems_by_groups.keys.compact.sort + [nil, ordered_groups].flatten.each do |groups| + gems = outdated_gems_by_groups[groups] + contains_group = if groups + groups.split(",").include?(options[:group]) + else + options[:group] == "group" + end + + next if (!options[:groups] && !contains_group) || gems.nil? + + 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], groups, options_include_groups.any?) + end + end + else + outdated_gems_list.each do |gem| + print_gem(gem[:current_spec], gem[:active_spec], gem[:dependency], gem[:groups], options_include_groups.any?) + end + end + exit 1 end end private + def print_gem(current_spec, active_spec, dependency, groups, options_include_groups) + 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 + elsif options_include_groups || !groups + Bundler.ui.info " * #{spec_outdated_info}".rstrip + else + Bundler.ui.info " * #{spec_outdated_info} in groups \"#{groups}\"".rstrip + end + end + def check_for_deployment_mode if Bundler.settings[:frozen] error_message = "You are trying to check outdated gems in deployment mode. " \ @@ -123,7 +167,6 @@ module Bundler active_major = active_spec.version.segments.first update_present = false - update_present = active_major > current_major if options[:major] if !update_present && (options[:minor] || options[:patch]) && current_major == active_major diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index 6420c28ac7..ab00e64b9d 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -72,6 +72,120 @@ describe "bundle outdated" do end end + describe "with --group option" do + def test_group_option(group = nil, gems_list_size = 1) + install_gemfile <<-G + source "file://#{gem_repo2}" + + gem "weakling", "~> 0.0.1" + gem "terranova", '8' + group :development, :test do + gem "duradura", '7.0' + gem 'activesupport', '2.3.5' + end + G + + update_repo2 do + build_gem "activesupport", "3.0" + build_gem "terranova", "9" + build_gem "duradura", "8.0" + end + + bundle "outdated --group #{group}" + + # Gem names are one per-line, between "*" and their parenthesized version. + gem_list = out.split("\n").map {|g| g[/\* (.*) \(/, 1] }.compact + expect(gem_list).to eq(gem_list.sort) + expect(gem_list.size).to eq gems_list_size + end + + it "not outdated gems" do + install_gemfile <<-G + source "file://#{gem_repo2}" + + gem "weakling", "~> 0.0.1" + gem "terranova", '8' + group :development, :test do + gem 'activesupport', '2.3.5' + gem "duradura", '7.0' + end + G + + bundle "outdated --group" + expect(out).to include("Bundle up to date!") + end + + it "returns a sorted list of outdated gems from one group => 'default'" do + test_group_option("default") + + expect(out).to include("===== Group default =====") + expect(out).to include("terranova (") + + expect(out).not_to include("===== Group development, test =====") + expect(out).not_to include("activesupport") + expect(out).not_to include("duradura") + end + + it "returns a sorted list of outdated gems from one group => 'development'" do + test_group_option("development", 2) + + expect(out).not_to include("===== Group default =====") + expect(out).not_to include("terranova (") + + expect(out).to include("===== Group development, test =====") + expect(out).to include("activesupport") + expect(out).to include("duradura") + end + end + + describe "with --groups option" do + it "not outdated gems" do + install_gemfile <<-G + source "file://#{gem_repo2}" + + gem "weakling", "~> 0.0.1" + gem "terranova", '8' + group :development, :test do + gem 'activesupport', '2.3.5' + gem "duradura", '7.0' + end + G + + bundle "outdated --groups" + expect(out).to include("Bundle up to date!") + end + + it "returns a sorted list of outdated gems by groups" do + install_gemfile <<-G + source "file://#{gem_repo2}" + + gem "weakling", "~> 0.0.1" + gem "terranova", '8' + group :development, :test do + gem 'activesupport', '2.3.5' + gem "duradura", '7.0' + end + G + + update_repo2 do + build_gem "activesupport", "3.0" + build_gem "terranova", "9" + build_gem "duradura", "8.0" + end + + bundle "outdated --groups" + expect(out).to include("===== Group default =====") + expect(out).to include("terranova (newest 9, installed 8, requested = 8)") + expect(out).to include("===== Group development, test =====") + expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)") + expect(out).to include("duradura (newest 8.0, installed 7.0, requested = 7.0)") + + expect(out).not_to include("weakling (") + + # TODO: check gems order inside the group + end + end + describe "with --local option" do it "doesn't hit repo2" do FileUtils.rm_rf(gem_repo2) |