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

Commit

Permalink
Add --parseable (with --porcelain alias) to bundle outdated for min…
Browse files Browse the repository at this point in the history
…imal output

- This flag changes the output of bundle outdated from:
```
  * activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5) in groups "development, test"
```
to
```
activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)"
```
and removes the extraneous output relating to fetching gem metadata,
version metadata, git updates, and resolving dependencies.

- Addresses rubygems/bundler-features#85
  • Loading branch information
RochesterinNYC committed Feb 5, 2016
1 parent 7db169c commit 25ea3d2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/bundler/cli.rb
Expand Up @@ -245,6 +245,8 @@ def binstubs(*gems)
"Only list newer versions allowed by your Gemfile requirements"
method_option "major", :type => :boolean, :banner => "Only list major newer versions"
method_option "minor", :type => :boolean, :banner => "Only list at least minor newer versions"
method_option "parseable", :aliases => "--porcelain", :type => :boolean, :banner =>
"Use minimal formatting for more parseable output"
def outdated(*gems)
require "bundler/cli/outdated"
Outdated.new(options, gems).run
Expand Down
32 changes: 23 additions & 9 deletions lib/bundler/cli/outdated.rb
Expand Up @@ -27,7 +27,13 @@ def run
else
definition = Bundler.definition(:gems => gems, :sources => sources)
end
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
definition_resolution.call
end

Bundler.ui.info ""

Expand Down Expand Up @@ -65,32 +71,40 @@ 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
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:"
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?

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

Bundler.ui.info " * #{active_spec.name} (newest #{spec_version}, installed #{current_version}#{dependency_version})#{groups}".rstrip
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
end
Bundler.ui.debug "from #{active_spec.loaded_from}"
end

if out_count.zero?
Bundler.ui.info "Bundle up to date!\n"
Bundler.ui.info "Bundle up to date!\n" unless options[:parseable]
else
exit 1
end
Expand Down
37 changes: 37 additions & 0 deletions spec/commands/outdated_spec.rb
Expand Up @@ -79,6 +79,43 @@
end
end

shared_examples_for "a minimal output is desired" do
context "and gems are outdated" do
before do
update_repo2 do
build_gem "activesupport", "3.0"
build_gem "weakling", "0.2"
end
end

it "outputs a sorted list of outdated gems with a more minimal format" do
minimal_output = "activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)\n" \
"weakling (newest 0.2, installed 0.0.3, requested ~> 0.0.1)"
subject
expect(out).to eq(minimal_output)
end
end

context "and no gems are outdated" do
it "has empty output" do
subject
expect(out).to eq("")
end
end
end

describe "with --parseable option" do
subject { bundle "outdated --parseable" }

it_behaves_like "a minimal output is desired"
end

describe "with aliased --porcelain option" do
subject { bundle "outdated --porcelain" }

it_behaves_like "a minimal output is desired"
end

describe "with specified gems" do
it "returns list of outdated gems" do
update_repo2 do
Expand Down

0 comments on commit 25ea3d2

Please sign in to comment.