summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederico Bittencourt <fred.rbittencourt@gmail.com>2016-10-15 15:07:19 -0300
committerFrederico Bittencourt <fred.rbittencourt@gmail.com>2016-10-15 15:07:19 -0300
commite5d61e093d28c7c9a4e002b135fb5d72284e3d1e (patch)
tree534619c4ee0c521b46b481100051ed0d041434de
parentbc746cbd8d13df66425f661371115ae092dcaff7 (diff)
downloadbundler-e5d61e093d28c7c9a4e002b135fb5d72284e3d1e.tar.gz
show specific gem details with 'bundle info GEM'
-rw-r--r--lib/bundler/cli.rb8
-rw-r--r--lib/bundler/cli/info.rb59
-rw-r--r--spec/commands/info_spec.rb37
3 files changed, 104 insertions, 0 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index f92ecb1c33..06dc5b208b 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -245,6 +245,14 @@ module Bundler
# TODO: 2.0 remove `bundle list`
map %w(list) => "show"
+ desc "info GEM [OPTIONS]", "Shows gem information"
+ method_option "path", :type => :boolean,
+ :banner => "Show gem path"
+ def info(gem_name)
+ require "bundler/cli/info"
+ Info.new(options, gem_name).run
+ end
+
desc "binstubs GEM [OPTIONS]", "Install the binstubs of the listed gem"
long_desc <<-D
Generate binstubs for executables in [GEM]. Binstubs are put into bin,
diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb
new file mode 100644
index 0000000000..54f7593ec7
--- /dev/null
+++ b/lib/bundler/cli/info.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+require "bundler/cli/common"
+
+module Bundler
+ class CLI::Info
+ attr_reader :gem_name, :options, :latest_specs
+ def initialize(options, gem_name)
+ @options = options
+ @gem_name = gem_name
+ @latest_specs = fetch_latest_specs if not options[:path]
+ end
+
+ def run
+ Bundler.ui.silence do
+ Bundler.definition.validate_runtime!
+ Bundler.load.lock
+ end
+
+ spec = Bundler::CLI::Common.select_spec(gem_name, :regex_match)
+ return unless spec
+
+ path = spec.full_gem_path
+ if options[:path]
+ return Bundler.ui.info(path)
+ end
+
+ unless File.directory?(path)
+ Bundler.ui.warn("The gem #{gem_name} has been deleted. It was installed at:")
+ end
+
+ return print_gem_info spec
+ end
+
+ private
+
+ def print_gem_info spec
+ desc = " * #{spec.name} (#{spec.version}#{spec.git_version})"
+ latest = latest_specs.find {|l| l.name == spec.name }
+ Bundler.ui.info <<-END.gsub(/^ +/, "")
+ #{desc}
+ \tSummary: #{spec.summary || "No description available."}
+ \tHomepage: #{spec.homepage || "No website available."}
+ \tStatus: #{outdated?(spec, latest) ? "Outdated - #{spec.version} < #{latest.version}" : "Up to date"}
+ END
+ end
+
+ def fetch_latest_specs
+ definition = Bundler.definition(true)
+ definition.resolve_remotely!
+ definition.specs
+ end
+
+ def outdated?(current, latest)
+ return false unless latest
+ Gem::Version.new(current.version) < Gem::Version.new(latest.version)
+ end
+
+ end
+end
diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb
new file mode 100644
index 0000000000..6366f7f9ed
--- /dev/null
+++ b/spec/commands/info_spec.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+require "spec_helper"
+
+describe "bunlde info" do
+
+ context "info from specific gem in gemfile" do
+ before :each do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rails"
+ G
+ end
+
+ it "should print summary of rake gem" do
+ bundle "info rails"
+
+ expect(out).to include("rails")
+ expect(out).to include("\tSummary:")
+ expect(out).to include("\tHomepage:")
+ expect(out).to include("\tStatus:")
+ end
+
+ it "should print gem path" do
+ bundle "info rails --path"
+ expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s)
+ end
+
+ it "should create a Gemfile.lock if not existing" do
+ FileUtils.rm("Gemfile.lock")
+
+ bundle "info rails"
+
+ expect(bundled_app("Gemfile.lock")).to exist
+ end
+
+ end
+end