Skip to content

Commit

Permalink
[rubygems/rubygems] Raise invalid option when bundle open --path is c…
Browse files Browse the repository at this point in the history
…alled without a value

rubygems/rubygems@c242311158
  • Loading branch information
yoka authored and matzbot committed Jan 4, 2023
1 parent 87c17a1 commit 799d805
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def exec(*args)
subcommand "config", Config

desc "open GEM", "Opens the source directory of the given bundled gem"
method_option "path", :type => :string, :banner => "Open relative path of the gem source."
method_option "path", :type => :string, :lazy_default => "", :banner => "Open relative path of the gem source."
def open(name)
require_relative "cli/open"
Open.new(options, name).run
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/open.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(options, name)
end

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)
Expand Down
5 changes: 5 additions & 0 deletions spec/bundler/commands/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
expect(out).to include("editor #{default_bundle_path("gems", "activerecord-2.3.2")}/lib/active_record")
end

it "requires value for --path arg" do
bundle "open activerecord --path", :env => { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }, :raise_on_error => false
expect(err).to eq "Cannot specify `--path` option without a value"
end

it "suggests alternatives for similar-sounding gems when using subpath" do
bundle "open Rails --path README.md", :env => { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }, :raise_on_error => false
expect(err).to match(/did you mean rails\?/i)
Expand Down

0 comments on commit 799d805

Please sign in to comment.