diff options
author | James Wen <jrw2175@columbia.edu> | 2016-02-04 01:29:32 -0500 |
---|---|---|
committer | James Wen <jrw2175@columbia.edu> | 2016-02-04 22:38:17 -0500 |
commit | 25ea3d23bb6b4cb356b4dfdebe8d9293b682d340 (patch) | |
tree | 698167c577a1eab5446980025c7004b3a73ffeb8 | |
parent | 7db169c6acd43abe57db66c80227ea3892abe703 (diff) | |
download | bundler-25ea3d23bb6b4cb356b4dfdebe8d9293b682d340.tar.gz |
Add --parseable (with --porcelain alias) to `bundle outdated` for minimal 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 bundler/bundler-features#85
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/outdated.rb | 32 | ||||
-rw-r--r-- | spec/commands/outdated_spec.rb | 37 |
3 files changed, 62 insertions, 9 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 2445172321..1fed1b58f0 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -245,6 +245,8 @@ module Bundler "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 diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 3c85d0bdcd..f2354465be 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -27,7 +27,13 @@ module Bundler 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 "" @@ -65,11 +71,13 @@ 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 - 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 @@ -77,20 +85,26 @@ module Bundler 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 diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index 5db12f0269..dcdb21ae66 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -79,6 +79,43 @@ describe "bundle outdated" do 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 |