summaryrefslogtreecommitdiff
path: root/lib/rubygems/commands
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/commands')
-rw-r--r--lib/rubygems/commands/dependency_command.rb15
-rw-r--r--lib/rubygems/commands/environment_command.rb2
-rw-r--r--lib/rubygems/commands/fetch_command.rb11
-rw-r--r--lib/rubygems/commands/install_command.rb1
-rw-r--r--lib/rubygems/commands/mirror_command.rb16
-rw-r--r--lib/rubygems/commands/owner_command.rb75
-rw-r--r--lib/rubygems/commands/pristine_command.rb2
-rw-r--r--lib/rubygems/commands/push_command.rb45
-rw-r--r--lib/rubygems/commands/query_command.rb5
-rw-r--r--lib/rubygems/commands/rdoc_command.rb33
-rw-r--r--lib/rubygems/commands/server_command.rb6
-rw-r--r--lib/rubygems/commands/setup_command.rb12
-rw-r--r--lib/rubygems/commands/unpack_command.rb4
-rw-r--r--lib/rubygems/commands/update_command.rb4
-rw-r--r--lib/rubygems/commands/which_command.rb16
15 files changed, 203 insertions, 44 deletions
diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb
index 44b269bb11..61e3b59fd7 100644
--- a/lib/rubygems/commands/dependency_command.rb
+++ b/lib/rubygems/commands/dependency_command.rb
@@ -15,6 +15,7 @@ class Gem::Commands::DependencyCommand < Gem::Command
add_version_option
add_platform_option
+ add_prerelease_option
add_option('-R', '--[no-]reverse-dependencies',
'Include reverse dependencies in the output') do
@@ -59,6 +60,7 @@ class Gem::Commands::DependencyCommand < Gem::Command
end
dependency = Gem::Dependency.new pattern, options[:version]
+ dependency.prerelease = options[:prerelease]
if options[:reverse_dependencies] and remote? and not local? then
alert_error 'Only reverse dependencies for local gems are supported.'
@@ -75,7 +77,10 @@ class Gem::Commands::DependencyCommand < Gem::Command
fetcher = Gem::SpecFetcher.fetcher
begin
- fetcher.find_matching(dependency).each do |spec_tuple, source_uri|
+ specs_and_sources = fetcher.find_matching(dependency, false, true,
+ dependency.prerelease?)
+
+ specs_and_sources.each do |spec_tuple, source_uri|
spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
source_indexes[source_uri].add_spec spec
@@ -120,8 +125,8 @@ class Gem::Commands::DependencyCommand < Gem::Command
if options[:pipe_format] then
specs.values.sort_by { |_, spec| spec }.each do |_, spec|
unless spec.dependencies.empty?
- spec.dependencies.each do |dep|
- say "#{dep.name} --version '#{dep.version_requirements}'"
+ spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
+ say "#{dep.name} --version '#{dep.requirement}'"
end
end
end
@@ -147,7 +152,7 @@ class Gem::Commands::DependencyCommand < Gem::Command
response = ''
response << ' ' * level + "Gem #{spec.full_name}\n"
unless spec.dependencies.empty? then
- spec.dependencies.each do |dep|
+ spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
response << ' ' * level + " #{dep}\n"
end
end
@@ -163,7 +168,7 @@ class Gem::Commands::DependencyCommand < Gem::Command
dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep
if spec.name == dep.name and
- dep.version_requirements.satisfied_by?(spec.version) then
+ dep.requirement.satisfied_by?(spec.version) then
result << [sp.full_name, dep]
end
end
diff --git a/lib/rubygems/commands/environment_command.rb b/lib/rubygems/commands/environment_command.rb
index e672da54f0..f3550cae28 100644
--- a/lib/rubygems/commands/environment_command.rb
+++ b/lib/rubygems/commands/environment_command.rb
@@ -118,7 +118,7 @@ lib/rubygems/defaults/operating_system.rb
end
else
- fail Gem::CommandLineError, "Unknown enviroment option [#{arg}]"
+ raise Gem::CommandLineError, "Unknown enviroment option [#{arg}]"
end
say out
true
diff --git a/lib/rubygems/commands/fetch_command.rb b/lib/rubygems/commands/fetch_command.rb
index 76c9924e6b..b12e1b4a5d 100644
--- a/lib/rubygems/commands/fetch_command.rb
+++ b/lib/rubygems/commands/fetch_command.rb
@@ -17,6 +17,7 @@ class Gem::Commands::FetchCommand < Gem::Command
add_version_option
add_platform_option
+ add_prerelease_option
end
def arguments # :nodoc:
@@ -39,12 +40,12 @@ class Gem::Commands::FetchCommand < Gem::Command
gem_names.each do |gem_name|
dep = Gem::Dependency.new gem_name, version
+ dep.prerelease = options[:prerelease]
- specs_and_sources = Gem::SpecFetcher.fetcher.fetch dep, all
+ specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, false, true,
+ dep.prerelease?)
- specs_and_sources.sort_by { |spec,| spec.version }
-
- spec, source_uri = specs_and_sources.last
+ spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last
if spec.nil? then
alert_error "Could not find #{gem_name} in any repository"
@@ -52,7 +53,7 @@ class Gem::Commands::FetchCommand < Gem::Command
end
path = Gem::RemoteFetcher.fetcher.download spec, source_uri
- FileUtils.mv path, "#{spec.full_name}.gem"
+ FileUtils.mv path, spec.file_name
say "Downloaded #{spec.full_name}"
end
diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb
index af2d8bd739..df6b3e5f2c 100644
--- a/lib/rubygems/commands/install_command.rb
+++ b/lib/rubygems/commands/install_command.rb
@@ -32,6 +32,7 @@ class Gem::Commands::InstallCommand < Gem::Command
add_local_remote_options
add_platform_option
add_version_option
+ add_prerelease_option "to be installed. (Only for listed gems)"
end
def arguments # :nodoc:
diff --git a/lib/rubygems/commands/mirror_command.rb b/lib/rubygems/commands/mirror_command.rb
index 959b8eaec3..7cb8583326 100644
--- a/lib/rubygems/commands/mirror_command.rb
+++ b/lib/rubygems/commands/mirror_command.rb
@@ -51,7 +51,7 @@ Multiple sources and destinations may be specified.
Dir.mkdir gems_dir
end
- sourceindex_data = ''
+ source_index_data = ''
say "fetching: #{get_from}/Marshal.#{Gem.marshal_version}.Z"
@@ -70,18 +70,18 @@ Multiple sources and destinations may be specified.
end
open File.join(get_from.to_s, "Marshal.#{Gem.marshal_version}.Z"), "rb" do |y|
- sourceindex_data = Zlib::Inflate.inflate y.read
+ source_index_data = Zlib::Inflate.inflate y.read
open File.join(save_to, "Marshal.#{Gem.marshal_version}"), "wb" do |out|
- out.write sourceindex_data
+ out.write source_index_data
end
end
- sourceindex = Marshal.load(sourceindex_data)
+ source_index = Marshal.load source_index_data
- progress = ui.progress_reporter sourceindex.size,
- "Fetching #{sourceindex.size} gems"
- sourceindex.each do |fullname, gem|
- gem_file = "#{fullname}.gem"
+ progress = ui.progress_reporter source_index.size,
+ "Fetching #{source_index.size} gems"
+ source_index.each do |fullname, gem|
+ gem_file = gem.file_name
gem_dest = File.join gems_dir, gem_file
unless File.exist? gem_dest then
diff --git a/lib/rubygems/commands/owner_command.rb b/lib/rubygems/commands/owner_command.rb
new file mode 100644
index 0000000000..e88734e8fb
--- /dev/null
+++ b/lib/rubygems/commands/owner_command.rb
@@ -0,0 +1,75 @@
+require 'rubygems/command'
+require 'rubygems/local_remote_options'
+require 'rubygems/gemcutter_utilities'
+
+class Gem::Commands::OwnerCommand < Gem::Command
+ include Gem::LocalRemoteOptions
+ include Gem::GemcutterUtilities
+
+ def description # :nodoc:
+ 'Manage gem owners on RubyGems.org.'
+ end
+
+ def arguments # :nodoc:
+ "GEM gem to manage owners for"
+ end
+
+ def initialize
+ super 'owner', description
+ add_proxy_option
+ defaults.merge! :add => [], :remove => []
+
+ add_option '-a', '--add EMAIL', 'Add an owner' do |value, options|
+ options[:add] << value
+ end
+
+ add_option '-r', '--remove EMAIL', 'Remove an owner' do |value, options|
+ options[:remove] << value
+ end
+ end
+
+ def execute
+ sign_in
+ name = get_one_gem_name
+
+ add_owners name, options[:add]
+ remove_owners name, options[:remove]
+ show_owners name
+ end
+
+ def show_owners name
+ response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request|
+ request.add_field "Authorization", Gem.configuration.rubygems_api_key
+ end
+
+ with_response response do |resp|
+ owners = YAML.load resp.body
+
+ say "Owners for gem: #{name}"
+ owners.each do |owner|
+ say "- #{owner['email']}"
+ end
+ end
+ end
+
+ def add_owners name, owners
+ manage_owners :post, name, owners
+ end
+
+ def remove_owners name, owners
+ manage_owners :delete, name, owners
+ end
+
+ def manage_owners method, name, owners
+ owners.each do |owner|
+ response = rubygems_api_request method, "api/v1/gems/#{name}/owners" do |request|
+ request.set_form_data 'email' => owner
+ request.add_field "Authorization", Gem.configuration.rubygems_api_key
+ end
+
+ with_response response
+ end
+ end
+
+end
+
diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb
index d47fe54edd..ef11129d2c 100644
--- a/lib/rubygems/commands/pristine_command.rb
+++ b/lib/rubygems/commands/pristine_command.rb
@@ -74,7 +74,7 @@ revert the gem.
say "Restoring gem(s) to pristine condition..."
specs.each do |spec|
- gem = Dir[File.join(Gem.dir, 'cache', "#{spec.full_name}.gem")].first
+ gem = Dir[File.join(Gem.dir, 'cache', spec.file_name)].first
if gem.nil? then
alert_error "Cached gem for #{spec.full_name} not found, use `gem install` to restore"
diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb
new file mode 100644
index 0000000000..cabcd3d94d
--- /dev/null
+++ b/lib/rubygems/commands/push_command.rb
@@ -0,0 +1,45 @@
+require 'rubygems/command'
+require 'rubygems/local_remote_options'
+require 'rubygems/gemcutter_utilities'
+
+class Gem::Commands::PushCommand < Gem::Command
+ include Gem::LocalRemoteOptions
+ include Gem::GemcutterUtilities
+
+ def description # :nodoc:
+ 'Push a gem up to RubyGems.org'
+ end
+
+ def arguments # :nodoc:
+ "GEM built gem to push up"
+ end
+
+ def usage # :nodoc:
+ "#{program_name} GEM"
+ end
+
+ def initialize
+ super 'push', description
+ add_proxy_option
+ end
+
+ def execute
+ sign_in
+ send_gem get_one_gem_name
+ end
+
+ def send_gem name
+ say "Pushing gem to RubyGems.org..."
+
+ response = rubygems_api_request :post, "api/v1/gems" do |request|
+ request.body = Gem.read_binary name
+ request.add_field "Content-Length", request.body.size
+ request.add_field "Content-Type", "application/octet-stream"
+ request.add_field "Authorization", Gem.configuration.rubygems_api_key
+ end
+
+ with_response response
+ end
+
+end
+
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb
index 88f7f0b54e..7dd0a4a0d6 100644
--- a/lib/rubygems/commands/query_command.rb
+++ b/lib/rubygems/commands/query_command.rb
@@ -45,7 +45,7 @@ class Gem::Commands::QueryCommand < Gem::Command
options[:all] = value
end
- add_option( '--prerelease',
+ add_option( '--[no-]prerelease',
'Display prerelease versions') do |value, options|
options[:prerelease] = value
end
@@ -111,6 +111,9 @@ class Gem::Commands::QueryCommand < Gem::Command
begin
fetcher = Gem::SpecFetcher.fetcher
spec_tuples = fetcher.find_matching dep, all, false, prerelease
+
+ spec_tuples += fetcher.find_matching dep, false, false, true if
+ prerelease and all
rescue Gem::RemoteFetcher::FetchError => e
if prerelease then
raise Gem::OperationNotSupportedError,
diff --git a/lib/rubygems/commands/rdoc_command.rb b/lib/rubygems/commands/rdoc_command.rb
index 92f215705a..ea0f3ad592 100644
--- a/lib/rubygems/commands/rdoc_command.rb
+++ b/lib/rubygems/commands/rdoc_command.rb
@@ -8,7 +8,7 @@ class Gem::Commands::RdocCommand < Gem::Command
def initialize
super 'rdoc', 'Generates RDoc for pre-installed gems',
:version => Gem::Requirement.default,
- :include_rdoc => true, :include_ri => true
+ :include_rdoc => true, :include_ri => true, :overwrite => false
add_option('--all',
'Generate RDoc/RI documentation for all',
@@ -17,15 +17,20 @@ class Gem::Commands::RdocCommand < Gem::Command
end
add_option('--[no-]rdoc',
- 'Include RDoc generated documents') do |value, options|
+ 'Generate RDoc HTML') do |value, options|
options[:include_rdoc] = value
end
add_option('--[no-]ri',
- 'Include RI generated documents') do |value, options|
+ 'Generate RI data') do |value, options|
options[:include_ri] = value
end
+ add_option('--[no-]overwrite',
+ 'Overwrite installed documents') do |value, options|
+ options[:overwrite] = value
+ end
+
add_version_option
end
@@ -34,7 +39,14 @@ class Gem::Commands::RdocCommand < Gem::Command
end
def defaults_str # :nodoc:
- "--version '#{Gem::Requirement.default}' --rdoc --ri"
+ "--version '#{Gem::Requirement.default}' --rdoc --ri --no-overwrite"
+ end
+
+ def description # :nodoc:
+ <<-DESC
+The rdoc command builds RDoc and RI documentation for installed gems. Use
+--overwrite to force rebuilding of documentation.
+ DESC
end
def usage # :nodoc:
@@ -53,24 +65,27 @@ class Gem::Commands::RdocCommand < Gem::Command
end
if specs.empty?
- fail "Failed to find gem #{gem_name} to generate RDoc for #{options[:version]}"
+ raise "Failed to find gem #{gem_name} to generate RDoc for #{options[:version]}"
end
if options[:include_ri]
- specs.each do |spec|
- Gem::DocManager.new(spec).generate_ri
+ specs.sort.each do |spec|
+ doc = Gem::DocManager.new(spec)
+ doc.generate_ri if options[:overwrite] || !doc.ri_installed?
end
Gem::DocManager.update_ri_cache
end
if options[:include_rdoc]
- specs.each do |spec|
- Gem::DocManager.new(spec).generate_rdoc
+ specs.sort.each do |spec|
+ doc = Gem::DocManager.new(spec)
+ doc.generate_rdoc if options[:overwrite] || !doc.rdoc_installed?
end
end
true
end
+
end
diff --git a/lib/rubygems/commands/server_command.rb b/lib/rubygems/commands/server_command.rb
index f8b990d304..6bc58367e9 100644
--- a/lib/rubygems/commands/server_command.rb
+++ b/lib/rubygems/commands/server_command.rb
@@ -36,6 +36,12 @@ class Gem::Commands::ServerCommand < Gem::Command
add_option '--[no-]daemon', 'run as a daemon' do |daemon, options|
options[:daemon] = daemon
end
+
+ add_option '-b', '--bind=HOST,HOST',
+ 'addresses to bind', Array do |address, options|
+ options[:addresses] ||= []
+ options[:addresses].push(*address)
+ end
end
def defaults_str # :nodoc:
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index 5bd5ebd468..f5f5185f86 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -2,7 +2,6 @@ require 'rubygems/command'
require 'fileutils'
require 'rbconfig'
require 'tmpdir'
-require 'pathname'
##
# Installs RubyGems itself. This command is ordinarily only available from a
@@ -117,6 +116,8 @@ By default, this RubyGems will install gem as:
say "RubyGems #{Gem::VERSION} installed"
+ uninstall_old_gemcutter
+
install_rdoc
say
@@ -359,5 +360,14 @@ abort "#{deprecation_message}"
r.document args
end
+ def uninstall_old_gemcutter
+ require 'rubygems/uninstaller'
+
+ ui = Gem::Uninstaller.new('gemcutter', :all => true, :ignore => true,
+ :version => '< 0.4')
+ ui.uninstall
+ rescue Gem::InstallError
+ end
+
end
diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb
index 075dc04203..84a53b107a 100644
--- a/lib/rubygems/commands/unpack_command.rb
+++ b/lib/rubygems/commands/unpack_command.rb
@@ -41,7 +41,7 @@ class Gem::Commands::UnpackCommand < Gem::Command
path = get_path name, options[:version]
if path then
- basename = File.basename(path).sub(/\.gem$/, '')
+ basename = File.basename(path, '.gem')
target_dir = File.expand_path File.join(options[:target], basename)
FileUtils.mkdir_p target_dir
Gem::Installer.new(path, :unpack => true).unpack target_dir
@@ -79,7 +79,7 @@ class Gem::Commands::UnpackCommand < Gem::Command
# We expect to find (basename).gem in the 'cache' directory.
# Furthermore, the name match must be exact (ignoring case).
if gemname =~ /^#{selected.name}$/i
- filename = selected.full_name + '.gem'
+ filename = selected.file_name
path = nil
Gem.path.find do |gem_dir|
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb
index 9974b2b54b..4b0439df1f 100644
--- a/lib/rubygems/commands/update_command.rb
+++ b/lib/rubygems/commands/update_command.rb
@@ -28,8 +28,8 @@ class Gem::Commands::UpdateCommand < Gem::Command
end
add_local_remote_options
-
add_platform_option
+ add_prerelease_option "as update targets"
end
def arguments # :nodoc:
@@ -51,7 +51,7 @@ class Gem::Commands::UpdateCommand < Gem::Command
say "Updating RubyGems"
unless options[:args].empty? then
- fail "No gem names are allowed with the --system option"
+ raise "No gem names are allowed with the --system option"
end
rubygems_update = Gem::Specification.new
diff --git a/lib/rubygems/commands/which_command.rb b/lib/rubygems/commands/which_command.rb
index 7c2d188324..b785f15660 100644
--- a/lib/rubygems/commands/which_command.rb
+++ b/lib/rubygems/commands/which_command.rb
@@ -27,13 +27,11 @@ class Gem::Commands::WhichCommand < Gem::Command
"--no-gems-first --no-all"
end
- def usage # :nodoc:
- "#{program_name} FILE [FILE ...]"
- end
-
def execute
searcher = Gem::GemPathSearcher.new
+ found = false
+
options[:args].each do |arg|
dirs = $LOAD_PATH
spec = searcher.find arg
@@ -44,19 +42,19 @@ class Gem::Commands::WhichCommand < Gem::Command
else
dirs = $LOAD_PATH + gem_paths(spec)
end
-
- say "(checking gem #{spec.full_name} for #{arg})" if
- Gem.configuration.verbose and $stdout.tty?
end
paths = find_paths arg, dirs
if paths.empty? then
- say "Can't find ruby library file or shared library #{arg}"
+ alert_error "Can't find ruby library file or shared library #{arg}"
else
say paths
+ found = true
end
end
+
+ terminate_interaction 1 unless found
end
def find_paths(package_name, dirs)
@@ -80,7 +78,7 @@ class Gem::Commands::WhichCommand < Gem::Command
end
def usage # :nodoc:
- "#{program_name} FILE [...]"
+ "#{program_name} FILE [FILE ...]"
end
end