Skip to content

Commit 39ff198

Browse files
Add --source option to gem exec command
Allows specifying a custom gem source when running `gem exec`, matching the existing --source option on gem install. Co-Authored-By: akshay-birajdar-zendesk <akshay.birajdar@zendesk.com>
1 parent 806a44b commit 39ff198

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

lib/rubygems/commands/exec_command.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
require_relative "../command"
44
require_relative "../dependency_installer"
55
require_relative "../gem_runner"
6+
require_relative "../local_remote_options"
67
require_relative "../package"
78
require_relative "../version_option"
89

910
class Gem::Commands::ExecCommand < Gem::Command
1011
include Gem::VersionOption
12+
include Gem::LocalRemoteOptions
1113

1214
def initialize
1315
super "exec", "Run a command from a gem", {
1416
version: Gem::Requirement.default,
1517
}
1618

19+
add_source_option
1720
add_version_option
1821
add_prerelease_option "to be installed"
1922

test/rubygems/test_gem_commands_exec_command.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,28 @@ def test_gem_with_executable
143143
end
144144
end
145145

146+
def test_gem_with_executable_from_custom_source
147+
spec_fetcher "http://other-gems.example.com/" do |fetcher|
148+
fetcher.gem "a", 2 do |s|
149+
s.executables = %w[a]
150+
s.files = %w[bin/a lib/a.rb]
151+
152+
write_file File.join(*%W[gems #{s.original_name} bin a]) do |f|
153+
f << "Gem.ui.say #{s.original_name.dump}"
154+
end
155+
end
156+
end
157+
158+
util_clear_gems
159+
160+
use_ui @ui do
161+
@cmd.invoke "--source", "http://other-gems.example.com", "a:2"
162+
assert_equal "a-2\n", @ui.output
163+
end
164+
165+
assert_include Gem.sources.to_a, "http://other-gems.example.com/"
166+
end
167+
146168
def test_gem_with_platforms
147169
spec_fetcher do |fetcher|
148170
fetcher.download "a", 2 do |s|

0 commit comments

Comments
 (0)