Skip to content

Commit 45e54d5

Browse files
hsbtclaude
andcommitted
Reject negative --cooldown values from the CLI
The Gemfile DSL already rejects `cooldown: -7`, but `--cooldown -7` on install/update/add/outdated slipped through Thor and ended up disabling the filter silently via the `days <= 0` short-circuit in the resolver. Add a shared CLI::Common.validate_cooldown! guard so the CLI surface fails loud with the same message as the DSL. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1f1309a commit 45e54d5

5 files changed

Lines changed: 10 additions & 0 deletions

File tree

bundler/lib/bundler/cli/add.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def initialize(options, gems)
1414
def run
1515
Bundler.ui.level = "warn" if options[:quiet]
1616

17+
Bundler::CLI::Common.validate_cooldown!(options[:cooldown])
1718
Bundler.settings.set_command_option_if_given :cooldown, options[:cooldown]
1819

1920
validate_options!

bundler/lib/bundler/cli/common.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
module Bundler
44
module CLI::Common
5+
def self.validate_cooldown!(value)
6+
return if value.nil?
7+
return if value.is_a?(Integer) && value >= 0
8+
raise InvalidOption, "Expected `--cooldown` to be a non-negative integer, got #{value.inspect}"
9+
end
10+
511
def self.output_post_install_messages(messages)
612
return if Bundler.settings["ignore_messages"]
713
messages.to_a.each do |name, msg|

bundler/lib/bundler/cli/install.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def normalize_settings
112112

113113
Bundler.settings.set_command_option_if_given :jobs, options["jobs"]
114114

115+
Bundler::CLI::Common.validate_cooldown!(options["cooldown"])
115116
Bundler.settings.set_command_option_if_given :cooldown, options["cooldown"]
116117

117118
Bundler.settings.set_command_option_if_given :no_prune, options["no-prune"]

bundler/lib/bundler/cli/outdated.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def initialize(options, gems)
2626
def run
2727
check_for_deployment_mode!
2828

29+
Bundler::CLI::Common.validate_cooldown!(options[:cooldown])
2930
Bundler.settings.set_command_option_if_given :cooldown, options[:cooldown]
3031

3132
Bundler.definition.validate_runtime!

bundler/lib/bundler/cli/update.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def run
6666
opts["force"] = options[:redownload] if options[:redownload]
6767

6868
Bundler.settings.set_command_option_if_given :jobs, opts["jobs"]
69+
Bundler::CLI::Common.validate_cooldown!(options[:cooldown])
6970
Bundler.settings.set_command_option_if_given :cooldown, options[:cooldown]
7071

7172
Bundler.definition.validate_runtime!

0 commit comments

Comments
 (0)