Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bundler/lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def update(*gems)
D
method_option "paths", type: :boolean, banner: "List the paths of all gems that are required by your Gemfile."
method_option "outdated", type: :boolean, banner: "Show verbose output including whether gems are outdated (removed)."
method_option "exact-match", type: :boolean, banner: "Only match gems whose names exactly match the given name"
def show(gem_name = nil)
if ARGV.include?("--outdated")
removed_message = "the `--outdated` flag to `bundle show` has been removed in favor of `bundle show --verbose`"
Expand All @@ -359,6 +360,7 @@ def list
desc "info GEM [OPTIONS]", "Show information for the given gem"
method_option "path", type: :boolean, banner: "Print full path to gem"
method_option "version", type: :boolean, banner: "Print gem version"
method_option "exact-match", type: :boolean, banner: "Only match gems whose names exactly match the given name"
def info(gem_name)
require_relative "cli/info"
Info.new(options, gem_name).run
Expand Down Expand Up @@ -519,6 +521,7 @@ def exec(*args)

desc "open GEM", "Opens the source directory of the given bundled gem"
method_option "path", type: :string, lazy_default: "", banner: "Open relative path of the gem source."
method_option "exact-match", type: :boolean, banner: "Only match gems whose names exactly match the given name"
def open(name)
require_relative "cli/open"
Open.new(options, name).run
Expand Down
4 changes: 4 additions & 0 deletions bundler/lib/bundler/cli/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def self.select_spec(name, regex_match = nil)
raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
end

def self.select_spec_with_match_type(name, options)
select_spec(name, options["exact-match"] ? nil : :regex_match)
end

def self.default_gem_spec(name)
gem_spec = Gem::Specification.find_all_by_name(name).last
gem_spec if gem_spec&.default_gem?
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/cli/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run
private

def spec_for_gem(name)
Bundler::CLI::Common.select_spec(name, :regex_match)
Bundler::CLI::Common.select_spec_with_match_type(name, options)
end

def print_gem_version(spec)
Expand Down
8 changes: 7 additions & 1 deletion bundler/lib/bundler/cli/open.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run
raise InvalidOption, "Cannot specify `--path` option without a value" if !@path.nil? && @path.empty?
editor = [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? }
return Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR") unless editor
return unless spec = Bundler::CLI::Common.select_spec(name, :regex_match)
return unless spec = spec_for_gem(name)
if spec.default_gem?
Bundler.ui.info "Unable to open #{name} because it's a default gem, so the directory it would normally be installed to does not exist."
else
Expand All @@ -25,5 +25,11 @@ def run
end || Bundler.ui.info("Could not run '#{command.join(" ")}'")
end
end

private

def spec_for_gem(name)
Bundler::CLI::Common.select_spec_with_match_type(name, options)
end
end
end
6 changes: 5 additions & 1 deletion bundler/lib/bundler/cli/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run
if gem_name == "bundler"
path = File.expand_path("../../..", __dir__)
else
spec = Bundler::CLI::Common.select_spec(gem_name, :regex_match)
spec = spec_for_gem(gem_name)
return unless spec
path = spec.full_gem_path
unless File.directory?(path)
Expand Down Expand Up @@ -55,6 +55,10 @@ def run

private

def spec_for_gem(name)
Bundler::CLI::Common.select_spec_with_match_type(name, options)
end

def fetch_latest_specs
definition = Bundler.definition(true)
Bundler.ui.info "Fetching remote specs for outdated check...\n\n"
Expand Down
5 changes: 4 additions & 1 deletion bundler/lib/bundler/man/bundle-info.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH "NAME"
\fBbundle\-info\fR \- Show information for the given gem in your bundle
.SH "SYNOPSIS"
\fBbundle info\fR [GEM_NAME] [\-\-path] [\-\-version]
\fBbundle info\fR [GEM_NAME] [\-\-path] [\-\-version] [\-\-exact\-match]
.SH "DESCRIPTION"
Given a gem name present in your bundle, print the basic information about it such as homepage, version, path and summary\.
.SH "OPTIONS"
Expand All @@ -14,4 +14,7 @@ Print the path of the given gem
.TP
\fB\-\-version\fR
Print gem version
.TP
\fB\-\-exact\-match\fR
Only match gems whose names exactly match the given name\.

4 changes: 4 additions & 0 deletions bundler/lib/bundler/man/bundle-info.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ bundle-info(1) -- Show information for the given gem in your bundle
`bundle info` [GEM_NAME]
[--path]
[--version]
[--exact-match]

## DESCRIPTION

Expand All @@ -19,3 +20,6 @@ Given a gem name present in your bundle, print the basic information about it

* `--version`:
Print gem version

* `--exact-match`:
Only match gems whose names exactly match the given name.
5 changes: 4 additions & 1 deletion bundler/lib/bundler/man/bundle-open.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH "NAME"
\fBbundle\-open\fR \- Opens the source directory for a gem in your bundle
.SH "SYNOPSIS"
\fBbundle open\fR [GEM] [\-\-path=PATH]
\fBbundle open\fR [GEM] [\-\-path=PATH] [\-\-exact\-match]
.SH "DESCRIPTION"
Opens the source directory of the provided GEM in your editor\.
.P
Expand All @@ -29,4 +29,7 @@ Will open the README\.md file of the 'rack' gem source in your bundle\.
.TP
\fB\-\-path[=PATH]\fR
Specify GEM source relative path to open\.
.TP
\fB\-\-exact\-match\fR
Only match gems whose names exactly match the given name\.

5 changes: 4 additions & 1 deletion bundler/lib/bundler/man/bundle-open.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bundle-open(1) -- Opens the source directory for a gem in your bundle

## SYNOPSIS

`bundle open` [GEM] [--path=PATH]
`bundle open` [GEM] [--path=PATH] [--exact-match]

## DESCRIPTION

Expand All @@ -26,3 +26,6 @@ Will open the README.md file of the 'rack' gem source in your bundle.

* `--path[=PATH]`:
Specify GEM source relative path to open.

* `--exact-match`:
Only match gems whose names exactly match the given name.
5 changes: 4 additions & 1 deletion bundler/lib/bundler/man/bundle-show.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH "NAME"
\fBbundle\-show\fR \- Shows all the gems in your bundle, or the path to a gem
.SH "SYNOPSIS"
\fBbundle show\fR [GEM] [\-\-paths]
\fBbundle show\fR [GEM] [\-\-paths] [\-\-exact\-match]
.SH "DESCRIPTION"
Without the [GEM] option, \fBshow\fR will print a list of the names and versions of all gems that are required by your [\fBGemfile(5)\fR][Gemfile(5)], sorted by name\.
.P
Expand All @@ -13,4 +13,7 @@ Calling show with [GEM] will list the exact location of that gem on your machine
.TP
\fB\-\-paths\fR
List the paths of all gems that are required by your [\fBGemfile(5)\fR][Gemfile(5)], sorted by gem name\.
.TP
\fB\-\-exact\-match\fR
Only match gems whose names exactly match the given name\.

4 changes: 4 additions & 0 deletions bundler/lib/bundler/man/bundle-show.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ bundle-show(1) -- Shows all the gems in your bundle, or the path to a gem

`bundle show` [GEM]
[--paths]
[--exact-match]

## DESCRIPTION

Expand All @@ -19,3 +20,6 @@ machine.
* `--paths`:
List the paths of all gems that are required by your [`Gemfile(5)`][Gemfile(5)],
sorted by gem name.

* `--exact-match`:
Only match gems whose names exactly match the given name.
30 changes: 28 additions & 2 deletions spec/commands/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,41 @@
end

context "with a valid regexp for gem name" do
it "presents alternatives", :readline do
it "returns the exact match without prompting when requested" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "info myrack --exact-match"
expect(out).to include("* myrack (1.0.0)")
expect(out).not_to include("0 : - exit -")
end

it "does not fall back to regexp matching when exact matching is requested" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "info rac --exact-match", raise_on_error: false
expect(err).to include("Could not find gem 'rac'.")
expect(out).not_to include("0 : - exit -")
end

it "presents alternatives without the exact match flag", :readline do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "info rac"
expect(out).to match(/\A1 : myrack\n2 : myrack-obama\n0 : - exit -(\n>|\z)/)
expect(out).to include("1 : myrack")
expect(out).to include("2 : myrack-obama")
expect(out).to include("0 : - exit -")
end
end

Expand Down
29 changes: 29 additions & 0 deletions spec/commands/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,33 @@
expect(out).to include("Unable to open json because it's a default gem, so the directory it would normally be installed to does not exist.")
end
end

context "with a valid regexp for gem name" do
before do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G
end

it "returns the exact match without prompting when requested" do
bundle "open myrack --exact-match", env: { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }
expect(out).to include("editor #{default_bundle_path("gems", "myrack-1.0.0")}")
expect(out).not_to include("0 : - exit -")
end

it "does not fall back to regexp matching when exact matching is requested" do
bundle "open rac --exact-match", env: { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }, raise_on_error: false
expect(err).to include("Could not find gem 'rac'.")
expect(out).not_to include("0 : - exit -")
end

it "presents alternatives without the exact match flag", :readline do
bundle "open rac", env: { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }
expect(out).to include("1 : myrack")
expect(out).to include("2 : myrack-obama")
expect(out).to include("0 : - exit -")
end
end
end
29 changes: 27 additions & 2 deletions spec/commands/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,40 @@
end

context "with a valid regexp for gem name" do
it "presents alternatives", :readline do
it "returns the exact match without prompting when requested" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "show myrack --exact-match"
expect(out).to include(default_bundle_path("gems", "myrack-1.0.0").to_s)
end

it "does not fall back to regexp matching when exact matching is requested" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "show rac --exact-match", raise_on_error: false
expect(err).to include("Could not find gem 'rac'.")
expect(out).not_to include("0 : - exit -")
end

it "presents alternatives without the exact match flag", :readline do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G

bundle "show rac"
expect(out).to match(/\A1 : myrack\n2 : myrack-obama\n0 : - exit -(\n>|\z)/)
expect(out).to include("1 : myrack")
expect(out).to include("2 : myrack-obama")
expect(out).to include("0 : - exit -")
end
end

Expand Down