diff options
Diffstat (limited to 'lib/rubygems/commands')
-rw-r--r-- | lib/rubygems/commands/build_command.rb | 57 | ||||
-rw-r--r-- | lib/rubygems/commands/cert_command.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/commands/help_command.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/commands/owner_command.rb | 12 | ||||
-rw-r--r-- | lib/rubygems/commands/pristine_command.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/commands/push_command.rb | 10 | ||||
-rw-r--r-- | lib/rubygems/commands/query_command.rb | 17 | ||||
-rw-r--r-- | lib/rubygems/commands/server_command.rb | 4 | ||||
-rw-r--r-- | lib/rubygems/commands/setup_command.rb | 70 | ||||
-rw-r--r-- | lib/rubygems/commands/sources_command.rb | 8 | ||||
-rw-r--r-- | lib/rubygems/commands/specification_command.rb | 6 | ||||
-rw-r--r-- | lib/rubygems/commands/yank_command.rb | 8 |
12 files changed, 120 insertions, 78 deletions
diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb index eaf8573d8f..fff5f7c76f 100644 --- a/lib/rubygems/commands/build_command.rb +++ b/lib/rubygems/commands/build_command.rb @@ -61,14 +61,18 @@ Gems can be saved to a specified filename with the output option: end def execute - gem_name = get_one_optional_argument || find_gemspec - build_gem(gem_name) + if build_path = options[:build_path] + Dir.chdir(build_path) { build_gem } + return + end + + build_gem end private - def find_gemspec - gemspecs = Dir.glob("*.gemspec").sort + def find_gemspec(glob = "*.gemspec") + gemspecs = Dir.glob(glob).sort if gemspecs.size > 1 alert_error "Multiple gemspecs found: #{gemspecs}, please specify one" @@ -78,28 +82,19 @@ Gems can be saved to a specified filename with the output option: gemspecs.first end - def build_gem(gem_name) - gemspec = File.exist?(gem_name) ? gem_name : "#{gem_name}.gemspec" - - if File.exist?(gemspec) - spec = Gem::Specification.load(gemspec) - - if options[:build_path] - Dir.chdir(File.dirname(gemspec)) do - spec = Gem::Specification.load(File.basename(gemspec)) - build_package(spec) - end - else - build_package(spec) - end + def build_gem + gemspec = resolve_gem_name + if gemspec + build_package(gemspec) else - alert_error "Gemspec file not found: #{gemspec}" + alert_error error_message terminate_interaction(1) end end - def build_package(spec) + def build_package(gemspec) + spec = Gem::Specification.load(gemspec) if spec Gem::Package.build( spec, @@ -112,4 +107,26 @@ Gems can be saved to a specified filename with the output option: terminate_interaction 1 end end + + def resolve_gem_name + return find_gemspec unless gem_name + + if File.exist?(gem_name) + gem_name + else + find_gemspec("#{gem_name}.gemspec") || find_gemspec(gem_name) + end + end + + def error_message + if gem_name + "Couldn't find a gemspec file matching '#{gem_name}' in #{Dir.pwd}" + else + "Couldn't find a gemspec file in #{Dir.pwd}" + end + end + + def gem_name + get_one_optional_argument + end end diff --git a/lib/rubygems/commands/cert_command.rb b/lib/rubygems/commands/cert_command.rb index e5355d3652..998df0621b 100644 --- a/lib/rubygems/commands/cert_command.rb +++ b/lib/rubygems/commands/cert_command.rb @@ -311,4 +311,4 @@ For further reading on signing gems see `ri Gem::Security`. # It's simple, but is all we need email =~ /\A.+@.+\z/ end -end if defined?(OpenSSL::SSL) +end if Gem::HAVE_OPENSSL diff --git a/lib/rubygems/commands/help_command.rb b/lib/rubygems/commands/help_command.rb index 9ba8bf1293..4e8d7600fb 100644 --- a/lib/rubygems/commands/help_command.rb +++ b/lib/rubygems/commands/help_command.rb @@ -332,6 +332,8 @@ platform. @command_manager.command_names.each do |cmd_name| command = @command_manager[cmd_name] + next if command.deprecated? + summary = if command command.summary diff --git a/lib/rubygems/commands/owner_command.rb b/lib/rubygems/commands/owner_command.rb index 0f01823967..46172854cf 100644 --- a/lib/rubygems/commands/owner_command.rb +++ b/lib/rubygems/commands/owner_command.rb @@ -53,7 +53,7 @@ permission to. def execute @host = options[:host] - sign_in + sign_in(scope: get_owner_scope) name = get_one_gem_name add_owners name, options[:add] @@ -102,10 +102,18 @@ permission to. private def send_owner_request(method, name, owner) - rubygems_api_request method, "api/v1/gems/#{name}/owners" do |request| + rubygems_api_request method, "api/v1/gems/#{name}/owners", scope: get_owner_scope(method: method) do |request| request.set_form_data 'email' => owner request.add_field "Authorization", api_key request.add_field "OTP", options[:otp] if options[:otp] end end + + def get_owner_scope(method: nil) + if method == :post || options.any? && options[:add].any? + :add_owner + elsif method == :delete || options.any? && options[:remove].any? + :remove_owner + end + end end diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index db8136c9a6..143105981e 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -170,7 +170,7 @@ extensions will be restored. :install_dir => spec.base_dir, :env_shebang => env_shebang, :build_args => spec.build_args, - :bin_dir => bin_dir + :bin_dir => bin_dir, } if options[:only_executables] diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index 003b2dacc7..8885269ecb 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -61,7 +61,7 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo options[:host] end - sign_in @host + sign_in @host, scope: get_push_scope send_gem(gem_name) end @@ -86,7 +86,7 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo private def send_push_request(name, args) - rubygems_api_request(*args) do |request| + rubygems_api_request(*args, scope: get_push_scope) do |request| request.body = Gem.read_binary name request.add_field "Content-Length", request.body.size request.add_field "Content-Type", "application/octet-stream" @@ -100,7 +100,11 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo [ gem_metadata["default_gem_server"], - gem_metadata["allowed_push_host"] + gem_metadata["allowed_push_host"], ] end + + def get_push_scope + :push_rubygem + end end diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb index 406a34e549..789afd6509 100644 --- a/lib/rubygems/commands/query_command.rb +++ b/lib/rubygems/commands/query_command.rb @@ -9,6 +9,14 @@ class Gem::Commands::QueryCommand < Gem::Command include Gem::QueryUtils + alias warning_without_suggested_alternatives deprecation_warning + def deprecation_warning + warning_without_suggested_alternatives + + message = "It is recommended that you use `gem search` or `gem list` instead.\n" + alert_warning message unless Gem::Deprecate.skip + end + def initialize(name = 'query', summary = 'Query gem information in local or remote repositories') super name, summary, @@ -23,4 +31,13 @@ class Gem::Commands::QueryCommand < Gem::Command add_query_options end + + def description # :nodoc: + <<-EOF +The query command is the basis for the list and search commands. + +You should really use the list and search commands instead. This command +is too hard to use. + EOF + end end diff --git a/lib/rubygems/commands/server_command.rb b/lib/rubygems/commands/server_command.rb index 91d5e267f8..594cf77f66 100644 --- a/lib/rubygems/commands/server_command.rb +++ b/lib/rubygems/commands/server_command.rb @@ -1,8 +1,12 @@ # frozen_string_literal: true require 'rubygems/command' require 'rubygems/server' +require 'rubygems/deprecate' class Gem::Commands::ServerCommand < Gem::Command + extend Gem::Deprecate + rubygems_deprecate_command + def initialize super 'server', 'Documentation and gem repository HTTP server', :port => 8808, :gemdir => [], :daemon => false diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index b63920ab8d..22b1371a1f 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -322,13 +322,10 @@ By default, this RubyGems will install gem as: libs.each do |tool, path| say "Installing #{tool}" if @verbose - lib_files = rb_files_in path - lib_files.concat(bundler_template_files) if tool == 'Bundler' - - pem_files = pem_files_in path + lib_files = files_in path Dir.chdir path do - install_file_list(lib_files + pem_files, lib_dir) + install_file_list(lib_files, lib_dir) end end end @@ -394,10 +391,6 @@ By default, this RubyGems will install gem as: specs_dir = File.join(options[:destdir], specs_dir) unless Gem.win_platform? mkdir_p specs_dir, :mode => 0755 - # Workaround for non-git environment. - gemspec = File.open('bundler/bundler.gemspec', 'rb'){|f| f.read.gsub(/`git ls-files -z`/, "''") } - File.open('bundler/bundler.gemspec', 'w'){|f| f.write gemspec } - bundler_spec = Gem::Specification.load("bundler/bundler.gemspec") bundler_spec.files = Dir.chdir("bundler") { Dir["{*.md,{lib,exe,man}/**/*}"] } bundler_spec.executables -= %w[bundler bundle_ruby] @@ -518,44 +511,24 @@ By default, this RubyGems will install gem as: [lib_dir, bin_dir] end - def pem_files_in(dir) - Dir.chdir dir do - Dir[File.join('**', '*pem')] - end - end - - def rb_files_in(dir) + def files_in(dir) Dir.chdir dir do - Dir[File.join('**', '*rb')] + Dir.glob(File.join('**', '*'), File::FNM_DOTMATCH). + select{|f| !File.directory?(f) } end end # for installation of bundler as default gems def bundler_man1_files_in(dir) Dir.chdir dir do - Dir['bundle*.1{,.txt,.ronn}'] + Dir['bundle*.1'] end end # for installation of bundler as default gems def bundler_man5_files_in(dir) Dir.chdir dir do - Dir['gemfile.5{,.txt,.ronn}'] - end - end - - def bundler_template_files - Dir.chdir "bundler/lib" do - Dir.glob(File.join('bundler', 'templates', '**', '*'), File::FNM_DOTMATCH). - select{|f| !File.directory?(f) } - end - end - - # for cleanup old bundler files - def template_files_in(dir) - Dir.chdir dir do - Dir.glob(File.join('templates', '**', '*'), File::FNM_DOTMATCH). - select{|f| !File.directory?(f) } + Dir['gemfile.5'] end end @@ -595,11 +568,9 @@ abort "#{deprecation_message}" lib_dirs = { File.join(lib_dir, 'rubygems') => 'lib/rubygems' } lib_dirs[File.join(lib_dir, 'bundler')] = 'bundler/lib/bundler' lib_dirs.each do |old_lib_dir, new_lib_dir| - lib_files = rb_files_in(new_lib_dir) - lib_files.concat(template_files_in(new_lib_dir)) if new_lib_dir =~ /bundler/ + lib_files = files_in(new_lib_dir) - old_lib_files = rb_files_in(old_lib_dir) - old_lib_files.concat(template_files_in(old_lib_dir)) if old_lib_dir =~ /bundler/ + old_lib_files = files_in(old_lib_dir) to_remove = old_lib_files - lib_files @@ -617,16 +588,25 @@ abort "#{deprecation_message}" def remove_old_man_files(man_dir) man_dirs = { man_dir => "bundler/man" } man_dirs.each do |old_man_dir, new_man_dir| - ["1", "5"].each do |section| - man_files = send(:"bundler_man#{section}_files_in", new_man_dir) + man1_files = bundler_man1_files_in(new_man_dir) - old_man_dir_with_section = "#{old_man_dir}/man#{section}" - old_man_files = send(:"bundler_man#{section}_files_in", old_man_dir_with_section) + old_man1_dir = "#{old_man_dir}/man1" + old_man1_files = bundler_man1_files_in(old_man1_dir) + old_man1_files += Dir.chdir(old_man1_dir) { Dir["bundle*.1.{txt,ronn}"] } - man_to_remove = old_man_files - man_files + man1_to_remove = old_man1_files - man1_files - remove_file_list(man_to_remove, old_man_dir_with_section) - end + remove_file_list(man1_to_remove, old_man1_dir) + + man5_files = bundler_man5_files_in(new_man_dir) + + old_man5_dir = "#{old_man_dir}/man5" + old_man5_files = bundler_man5_files_in(old_man5_dir) + old_man5_files += Dir.chdir(old_man5_dir) { Dir["gemfile.5.{txt,ronn}"] } + + man5_to_remove = old_man5_files - man5_files + + remove_file_list(man5_to_remove, old_man5_dir) end end diff --git a/lib/rubygems/commands/sources_command.rb b/lib/rubygems/commands/sources_command.rb index 3be3a5dc79..f74fb12e42 100644 --- a/lib/rubygems/commands/sources_command.rb +++ b/lib/rubygems/commands/sources_command.rb @@ -34,6 +34,10 @@ class Gem::Commands::SourcesCommand < Gem::Command options[:update] = value end + add_option '-f', '--[no-]force', "Do not show any confirmation prompts and behave as if 'yes' was always answered" do |value, options| + options[:force] = value + end + add_proxy_option end @@ -71,7 +75,7 @@ class Gem::Commands::SourcesCommand < Gem::Command Do you want to add this source? QUESTION - terminate_interaction 1 unless ask_yes_no question + terminate_interaction 1 unless options[:force] || ask_yes_no(question) end end @@ -86,7 +90,7 @@ https://rubygems.org is recommended for security over #{uri} Do you want to add this insecure source? QUESTION - terminate_interaction 1 unless ask_yes_no question + terminate_interaction 1 unless options[:force] || ask_yes_no(question) end end diff --git a/lib/rubygems/commands/specification_command.rb b/lib/rubygems/commands/specification_command.rb index e4a8afab21..3fddaaaf30 100644 --- a/lib/rubygems/commands/specification_command.rb +++ b/lib/rubygems/commands/specification_command.rb @@ -126,6 +126,12 @@ Specific fields in the specification can be extracted in YAML format: terminate_interaction 1 end + platform = get_platform_from_requirements(options) + + if platform + specs = specs.select{|s| s.platform.to_s == platform } + end + unless options[:all] specs = [specs.max_by {|s| s.version }] end diff --git a/lib/rubygems/commands/yank_command.rb b/lib/rubygems/commands/yank_command.rb index 6ad74de96b..0e08bbfd5d 100644 --- a/lib/rubygems/commands/yank_command.rb +++ b/lib/rubygems/commands/yank_command.rb @@ -47,7 +47,7 @@ data you will need to change them immediately and yank your gem. def execute @host = options[:host] - sign_in @host + sign_in @host, scope: get_yank_scope version = get_version_from_requirements(options[:version]) platform = get_platform_from_requirements(options) @@ -72,7 +72,7 @@ data you will need to change them immediately and yank your gem. def yank_api_request(method, version, platform, api) name = get_one_gem_name - response = rubygems_api_request(method, api, host) do |request| + response = rubygems_api_request(method, api, host, scope: get_yank_scope) do |request| request.add_field("Authorization", api_key) request.add_field("OTP", options[:otp]) if options[:otp] @@ -93,7 +93,7 @@ data you will need to change them immediately and yank your gem. nil end - def get_platform_from_requirements(requirements) - Gem.platforms[1].to_s if requirements.key? :added_platform + def get_yank_scope + :yank_rubygem end end |