[rubygems/rubygems] Raise invalid option when bundle open --path is called without a value

https://github.com/rubygems/rubygems/commit/c242311158
This commit is contained in:
yoka 2022-12-31 10:58:34 +02:00 committed by git
parent 87c17a141d
commit 799d805e21
3 changed files with 7 additions and 1 deletions

View File

@ -509,7 +509,7 @@ module Bundler
subcommand "config", Config subcommand "config", Config
desc "open GEM", "Opens the source directory of the given bundled gem" 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) def open(name)
require_relative "cli/open" require_relative "cli/open"
Open.new(options, name).run Open.new(options, name).run

View File

@ -10,6 +10,7 @@ module Bundler
end end
def run 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? } 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 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 = Bundler::CLI::Common.select_spec(name, :regex_match)

View File

@ -73,6 +73,11 @@ RSpec.describe "bundle open" do
expect(out).to include("editor #{default_bundle_path("gems", "activerecord-2.3.2")}/lib/active_record") expect(out).to include("editor #{default_bundle_path("gems", "activerecord-2.3.2")}/lib/active_record")
end 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 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 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) expect(err).to match(/did you mean rails\?/i)