diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-06-01 12:45:11 +0300 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-06-01 13:50:41 +0300 |
commit | 56660de3c6df7a4ff8667ef4047d30d0de169935 (patch) | |
tree | dd1e526075687b4b24e089cee50eabc21a6143cc /lib/rubygems/commands | |
parent | 560cd5b1f04f30542a294b3d77527d3b12f7cc15 (diff) | |
download | ruby-56660de3c6df7a4ff8667ef4047d30d0de169935.tar.gz |
Merge rubygems master from upstream.
I picked the commit from 3c469e0da538428a0ddd94f99aa73c32da22e8ba
Diffstat (limited to 'lib/rubygems/commands')
-rw-r--r-- | lib/rubygems/commands/pristine_command.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/commands/query_command.rb | 170 | ||||
-rw-r--r-- | lib/rubygems/commands/setup_command.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/commands/update_command.rb | 4 |
4 files changed, 95 insertions, 83 deletions
diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index a25b690afc..e4628bdd40 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -104,7 +104,7 @@ extensions will be restored. end.flatten end - specs = specs.select{|spec| RUBY_ENGINE == spec.platform || Gem::Platform.local === spec.platform } + specs = specs.select{|spec| RUBY_ENGINE == spec.platform || Gem::Platform.local === spec.platform || spec.platform == Gem::Platform::RUBY } if specs.to_a.empty? raise Gem::Exception, diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb index 5a42d45249..4fb23bc6c1 100644 --- a/lib/rubygems/commands/query_command.rb +++ b/lib/rubygems/commands/query_command.rb @@ -78,46 +78,58 @@ is too hard to use. end def execute + gem_names = Array(options[:name]) + + if !args.empty? + gem_names = options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i } + end + + terminate_interaction(check_installed_gems(gem_names)) if check_installed_gems? + + gem_names.each { |n| show_gems(n) } + end + + private + + def check_installed_gems(gem_names) exit_code = 0 - if options[:args].to_a.empty? and options[:name].source.empty? - name = options[:name] - no_name = true - elsif !options[:name].source.empty? - name = Array(options[:name]) + + if args.empty? && !gem_name? + alert_error "You must specify a gem name" + exit_code = 4 + elsif gem_names.count > 1 + alert_error "You must specify only ONE gem!" + exit_code = 4 else - args = options[:args].to_a - name = options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i } + installed = installed?(gem_names.first, options[:version]) + installed = !installed unless options[:installed] + + say(installed) + exit_code = 1 if !installed end - prerelease = options[:prerelease] + exit_code + end - unless options[:installed].nil? - if no_name - alert_error "You must specify a gem name" - exit_code |= 4 - elsif name.count > 1 - alert_error "You must specify only ONE gem!" - exit_code |= 4 - else - installed = installed? name.first, options[:version] - installed = !installed unless options[:installed] + def check_installed_gems? + !options[:installed].nil? + end - if installed - say "true" - else - say "false" - exit_code |= 1 - end - end + def gem_name? + !options[:name].source.empty? + end - terminate_interaction exit_code - end + def prerelease + options[:prerelease] + end - names = Array(name) - names.each { |n| show_gems n, prerelease } + def show_prereleases? + prerelease.nil? || prerelease end - private + def args + options[:args].to_a + end def display_header(type) if (ui.outs.tty? and Gem.configuration.verbose) or both? @@ -128,56 +140,57 @@ is too hard to use. end #Guts of original execute - def show_gems(name, prerelease) - req = Gem::Requirement.default - # TODO: deprecate for real + def show_gems(name) + show_local_gems(name) if local? + show_remote_gems(name) if remote? + end + + def show_local_gems(name, req = Gem::Requirement.default) + display_header("LOCAL") + + specs = Gem::Specification.find_all do |s| + s.name =~ name and req =~ s.version + end + dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req } - dep.prerelease = prerelease + specs.select! do |s| + dep.match?(s.name, s.version, show_prereleases?) + end - if local? - if prerelease and not both? - alert_warning "prereleases are always shown locally" - end + spec_tuples = specs.map do |spec| + [spec.name_tuple, spec] + end + + output_query_results(spec_tuples) + end - display_header 'LOCAL' + def show_remote_gems(name) + display_header("REMOTE") - specs = Gem::Specification.find_all do |s| - s.name =~ name and req =~ s.version - end + fetcher = Gem::SpecFetcher.fetcher - spec_tuples = specs.map do |spec| - [spec.name_tuple, spec] - end + spec_tuples = if name.respond_to?(:source) && name.source.empty? + fetcher.detect(specs_type) { true } + else + fetcher.detect(specs_type) do |name_tuple| + name === name_tuple.name + end + end - output_query_results spec_tuples - end + output_query_results(spec_tuples) + end - if remote? - display_header 'REMOTE' - - fetcher = Gem::SpecFetcher.fetcher - - type = if options[:all] - if options[:prerelease] - :complete - else - :released - end - elsif options[:prerelease] - :prerelease - else - :latest - end - - if name.respond_to?(:source) && name.source.empty? - spec_tuples = fetcher.detect(type) { true } + def specs_type + if options[:all] + if options[:prerelease] + :complete else - spec_tuples = fetcher.detect(type) do |name_tuple| - name === name_tuple.name - end + :released end - - output_query_results spec_tuples + elsif options[:prerelease] + :prerelease + else + :latest end end @@ -235,7 +248,7 @@ is too hard to use. name_tuple, spec = detail_tuple - spec = spec.fetch_spec name_tuple if spec.respond_to? :fetch_spec + spec = spec.fetch_spec(name_tuple)if spec.respond_to?(:fetch_spec) entry << "\n" @@ -285,8 +298,8 @@ is too hard to use. entry = [name_tuples.first.name] - entry_versions entry, name_tuples, platforms, specs - entry_details entry, detail_tuple, specs, platforms + entry_versions(entry, name_tuples, platforms, specs) + entry_details(entry, detail_tuple, specs, platforms) entry.join end @@ -337,12 +350,13 @@ is too hard to use. if platforms.length == 1 title = platforms.values.length == 1 ? 'Platform' : 'Platforms' - entry << " #{title}: #{platforms.values.sort.join ', '}\n" + entry << " #{title}: #{platforms.values.sort.join(', ')}\n" else entry << " Platforms:\n" - platforms.sort_by do |version,| - version - end.each do |version, pls| + + sorted_platforms = platforms.sort_by { |version,| version } + + sorted_platforms.each do |version, pls| label = " #{version}: " data = format_text pls.sort.join(', '), 68, label.length data[0, label.length] = label diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index f5e5236a06..1754630c8c 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -429,7 +429,7 @@ By default, this RubyGems will install gem as: Dir.chdir("bundler") do built_gem = Gem::Package.build(bundler_spec) begin - installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], install_as_default: true, bin_dir: bin_dir, wrappers: true) + installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], format_executable: options[:format_executable], install_as_default: true, bin_dir: bin_dir, wrappers: true) installer.install ensure FileUtils.rm_f built_gem diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 4b182396f3..e8031a259d 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -254,9 +254,7 @@ command to remove old versions. def update_rubygems_arguments # :nodoc: args = [] args << '--prefix' << Gem.prefix if Gem.prefix - # TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9 - args << '--no-rdoc' unless options[:document].include? 'rdoc' - args << '--no-ri' unless options[:document].include? 'ri' + args << '--no-document' unless options[:document].include?('rdoc') || options[:document].include?('ri') args << '--no-format-executable' if options[:no_format_executable] args << '--previous-version' << Gem::VERSION if options[:system] == true or |