From 4ae3df42f723d25b0fe4ba6b2689d607b01c6f48 Mon Sep 17 00:00:00 2001 From: hsbt Date: Thu, 14 Feb 2019 12:59:03 +0000 Subject: Merge RubyGems master@9be7858f7f17eae3058204f3c03e4b798ba18b9c This version contains the some style changes by RuboCop. * https://github.com/rubygems/rubygems/commit/9d810be0ede925fb2e3af535848582c3f8e0e72f * https://github.com/rubygems/rubygems/commit/61ea98a727fb1b76b6fac52d74107ee4b02aaef2 * https://github.com/rubygems/rubygems/commit/795893dce3c5f8540804fc08144cc6a90f086b13 * https://github.com/rubygems/rubygems/commit/9be7858f7f17eae3058204f3c03e4b798ba18b9c git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/command.rb | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'lib/rubygems/command.rb') diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index 5b8868b0cd..a509b783dd 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -122,6 +122,7 @@ class Gem::Command @defaults = defaults @options = defaults.dup @option_groups = Hash.new { |h,k| h[k] = [] } + @deprecated_options = { command => {} } @parser = nil @when_invoked = nil end @@ -365,13 +366,34 @@ class Gem::Command end end + def deprecate_option(short_name: nil, long_name: nil, version: nil) + @deprecated_options[command].merge!({ short_name => { "rg_version_to_expire" => version } }) if short_name + @deprecated_options[command].merge!({ long_name => { "rg_version_to_expire" => version } }) if long_name + end + + def check_deprecated_options(options) + options.each do |option| + if option_is_deprecated?(option) + version_to_expire = @deprecated_options[command][option]["rg_version_to_expire"] + + deprecate_option_msg = if version_to_expire + "The \"#{option}\" option has been deprecated and will be removed in Rubygems #{version_to_expire}, its use is discouraged." + else + "The \"#{option}\" option has been deprecated and will be removed in future versions of Rubygems, its use is discouraged." + end + + alert_warning(deprecate_option_msg) + end + end + end + ## # Merge a set of command options with the set of default options (without # modifying the default option hash). def merge_options(new_options) @options = @defaults.clone - new_options.each do |k,v| @options[k] = v end + new_options.each { |k,v| @options[k] = v } end ## @@ -392,6 +414,7 @@ class Gem::Command def handle_options(args) args = add_extra_args(args) + check_deprecated_options(args) @options = Marshal.load Marshal.dump @defaults # deep copy parser.parse!(args) @options[:args] = args @@ -420,6 +443,10 @@ class Gem::Command private + def option_is_deprecated?(option) + @deprecated_options[command].has_key?(option) + end + def add_parser_description # :nodoc: return unless description -- cgit v1.2.3