summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2026-01-26 17:01:07 +0900
committergit <svn-admin@ruby-lang.org>2026-02-13 03:09:16 +0000
commit5d39c1a41f6a86f4cbab325a6ba7bcdc6aadc831 (patch)
tree7860fb94bdd0262a91739edb0eeb1ac0db94a37f
parent6dbece090f74345c404b644445563d900cabb147 (diff)
[ruby/rubygems] Add support for help flag in plugin commands
https://github.com/ruby/rubygems/commit/b8d45956d0
-rw-r--r--lib/bundler/cli.rb4
-rw-r--r--spec/bundler/plugins/command_spec.rb31
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 1f6a65ca57..0f234f26b9 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -155,6 +155,10 @@ module Bundler
def help(cli = nil)
cli = self.class.all_aliases[cli] if self.class.all_aliases[cli]
+ if Bundler.settings[:plugins] && Bundler::Plugin.command?(cli) && !self.class.all_commands.key?(cli)
+ return Bundler::Plugin.exec_command(cli, ["--help"])
+ end
+
case cli
when "gemfile" then command = "gemfile"
when nil then command = "bundle"
diff --git a/spec/bundler/plugins/command_spec.rb b/spec/bundler/plugins/command_spec.rb
index f8dacb0e51..7dca1aae19 100644
--- a/spec/bundler/plugins/command_spec.rb
+++ b/spec/bundler/plugins/command_spec.rb
@@ -53,6 +53,37 @@ RSpec.describe "command plugins" do
expect(out).to eq("You gave me tacos, tofu, lasange")
end
+ it "passes help flag to plugin" do
+ update_repo2 do
+ build_plugin "helpful" do |s|
+ s.write "plugins.rb", <<-RUBY
+ module Helpful
+ class Command
+ Bundler::Plugin::API.command "greet", self
+
+ def exec(command, args)
+ if args.include?("--help") || args.include?("-h")
+ puts "Usage: bundle greet [NAME]"
+ else
+ puts "Hello"
+ end
+ end
+ end
+ end
+ RUBY
+ end
+ end
+
+ bundle "plugin install helpful --source https://gem.repo2"
+ expect(out).to include("Installed plugin helpful")
+
+ bundle "greet --help"
+ expect(out).to eq("Usage: bundle greet [NAME]")
+
+ bundle "greet -h"
+ expect(out).to eq("Usage: bundle greet [NAME]")
+ end
+
it "raises error on redeclaration of command" do
update_repo2 do
build_plugin "copycat" do |s|