This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #5374 - colby-swandale:bundle-info, r=indirect
Bundle info command This is a continuation of #5093 This PR adds a new command called `info` that is nearly identical to the `show` command, specifically `show <gem> --verbose`. Example: ``` › dbundler info rack * rack (2.0.1) Summary: a modular Ruby webserver interface Homepage: http://rack.github.io/ Path: /Users/colby/.gem/ruby/2.4.0/gems/rack-2.0.1 ``` There is also a option called `--path` that only prints the path to the gem ``` › dbundler info rack --path /Users/colby/.gem/ruby/2.4.0/gems/rack-2.0.1 ``` One noticeable difference between `info` and `show --verbose` is that i have removed the `outdated` functionality. This was made for several reasons: * There are currently problems with that functionality which have been raised in #5375 * We have a dedicated command called `outdated` for the user to get information about the outdated status of gems. * The outdated status requires an active internet connection and time to download the necessary information. I think not having to download anything and limiting `info` to just read information it already has would make for a more responsive and better user experience.
- Loading branch information
Showing
6 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
require "bundler/cli/common" | ||
|
||
module Bundler | ||
class CLI::Info | ||
attr_reader :gem_name, :options | ||
def initialize(options, gem_name) | ||
@options = options | ||
@gem_name = gem_name | ||
end | ||
|
||
def run | ||
spec = spec_for_gem(gem_name) | ||
|
||
spec_not_found(gem_name) unless spec | ||
return print_gem_path(spec) if @options[:path] | ||
print_gem_info(spec) | ||
end | ||
|
||
private | ||
|
||
def spec_for_gem(gem_name) | ||
spec = Bundler.definition.specs.find {|s| s.name == gem_name } | ||
spec || default_gem_spec(gem_name) | ||
end | ||
|
||
def default_gem_spec(gem_name) | ||
return unless Gem::Specification.respond_to?(:find_all_by_name) | ||
gem_spec = Gem::Specification.find_all_by_name(gem_name).last | ||
return gem_spec if gem_spec && gem_spec.respond_to?(:default_gem?) && gem_spec.default_gem? | ||
end | ||
|
||
def spec_not_found(gem_name) | ||
raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(gem_name, Bundler.definition.dependencies) | ||
end | ||
|
||
def print_gem_path(spec) | ||
Bundler.ui.info spec.full_gem_path | ||
end | ||
|
||
def print_gem_info(spec) | ||
gem_info = String.new | ||
gem_info << " * #{spec.name} (#{spec.version}#{spec.git_version})\n" | ||
gem_info << "\tSummary: #{spec.summary}\n" if spec.summary | ||
gem_info << "\tHomepage: #{spec.homepage}\n" if spec.homepage | ||
gem_info << "\tPath: #{spec.full_gem_path}\n" | ||
gem_info << "\tDefault Gem: yes" if spec.respond_to?(:default_gem?) && spec.default_gem? | ||
Bundler.ui.info gem_info | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
bundle-info(1) -- Show information for the given gem in your bundle | ||
========================================================================= | ||
|
||
## SYNOPSIS | ||
|
||
`bundle info` [GEM] | ||
[--path] | ||
|
||
## DESCRIPTION | ||
|
||
Print the basic information about the provided GEM such as homepage, version, | ||
path and summary. | ||
|
||
## OPTIONS | ||
|
||
* `--path`: | ||
Print the path of the given gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
require "spec_helper" | ||
|
||
RSpec.describe "bundle info" do | ||
context "info from specific gem in gemfile" do | ||
before do | ||
install_gemfile <<-G | ||
source "file://#{gem_repo1}" | ||
gem "rails" | ||
G | ||
end | ||
|
||
it "prints information about the current gem" do | ||
bundle "info rails" | ||
expect(out).to include "* rails (2.3.2) | ||
\tSummary: This is just a fake gem for testing | ||
\tHomepage: http://example.com" | ||
expect(out).to match(%r{Path\: .*\/rails\-2\.3\.2}) | ||
end | ||
|
||
context "given a gem that is not installed" do | ||
it "prints missing gem error" do | ||
bundle "info foo" | ||
expect(out).to eq "Could not find gem 'foo'." | ||
end | ||
end | ||
|
||
context "given a default gem shippped in ruby" do | ||
it "prints information about the default gem", :if => (RUBY_VERSION >= "2.0") do | ||
bundle "info rdoc" | ||
expect(out).to include("* rdoc") | ||
expect(out).to include("Default Gem: yes") | ||
end | ||
end | ||
|
||
context "when gem does not have homepage" do | ||
before do | ||
build_repo1 do | ||
build_gem "rails", "2.3.2" do |s| | ||
s.executables = "rails" | ||
s.summary = "Just another test gem" | ||
end | ||
end | ||
end | ||
|
||
it "excludes the homepage field from the output" do | ||
expect(out).to_not include("Homepage:") | ||
end | ||
end | ||
|
||
context "given --path option" do | ||
it "prints the path to the gem" do | ||
bundle "info rails" | ||
expect(out).to match(%r{.*\/rails\-2\.3\.2}) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters