class Bundler::CLI::Outdated

def run

def run
  check_for_deployment_mode
  sources = Array(options[:source])
  gems.each do |gem_name|
    Bundler::CLI::Common.select_spec(gem_name)
  end
  Bundler.definition.validate_runtime!
  current_specs = Bundler.ui.silence { Bundler.definition.resolve }
  current_dependencies = {}
  Bundler.ui.silence do
    Bundler.load.dependencies.each do |dep|
      current_dependencies[dep.name] = dep
    end
  end
  definition = if gems.empty? && sources.empty?
    # We're doing a full update
    Bundler.definition(true)
  else
    Bundler.definition(:gems => gems, :sources => sources)
  end
  Bundler::CLI::Common.configure_gem_version_promoter(
    Bundler.definition,
    options
  )
  # the patch level options imply strict is also true. It wouldn't make
  # sense otherwise.
  strict = options[:strict] ||
    Bundler::CLI::Common.patch_level_options(options).any?
  filter_options_patch = options.keys &
    %w[filter-major filter-minor filter-patch]
  definition_resolution = proc do
    options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!
  end
  if options[:parseable]
    Bundler.ui.silence(&definition_resolution)
  else
    definition_resolution.call
  end
  Bundler.ui.info ""
  outdated_gems_by_groups = {}
  outdated_gems_list = []
  # Loop through the current specs
  gemfile_specs, dependency_specs = current_specs.partition do |spec|
    current_dependencies.key? spec.name
  end
  (gemfile_specs + dependency_specs).sort_by(&:name).each do |current_spec|
    next if !gems.empty? && !gems.include?(current_spec.name)
    dependency = current_dependencies[current_spec.name]
    active_spec = retrieve_active_spec(strict, definition, current_spec)
    next if active_spec.nil?
    if filter_options_patch.any?
      update_present = update_present_via_semver_portions(current_spec, active_spec, options)
      next unless update_present
    end
    gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
    next unless gem_outdated || (current_spec.git_version != active_spec.git_version)
    groups = nil
    if dependency && !options[:parseable]
      groups = dependency.groups.join(", ")
    end
    outdated_gems_list << { :active_spec => active_spec,
                            :current_spec => current_spec,
                            :dependency => dependency,
                            :groups => groups }
    outdated_gems_by_groups[groups] ||= []
    outdated_gems_by_groups[groups] << { :active_spec => active_spec,
                                         :current_spec => current_spec,
                                         :dependency => dependency,
                                         :groups => groups }
  end
  if outdated_gems_list.empty?
    display_nothing_outdated_message(filter_options_patch)
  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 do |v|
      options.keys.include?(v.to_s)
    end
    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