summaryrefslogtreecommitdiff
path: root/lib/rubygems/command.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 06:52:18 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 06:52:18 +0000
commit9694bb8cac12969300692dac5a1cf7aa4e3a46cd (patch)
treec3cb423d701f7049ba9382de052e2a937cd1302d /lib/rubygems/command.rb
parent3f606b7063fc7a8b191556365ad343a314719a8d (diff)
downloadruby-9694bb8cac12969300692dac5a1cf7aa4e3a46cd.tar.gz
* lib/rubygems*: Updated to RubyGems 2.0
* test/rubygems*: ditto. * common.mk (prelude): Updated for RubyGems 2.0 source rearrangement. * tool/change_maker.rb: Allow invalid UTF-8 characters in source files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/command.rb')
-rw-r--r--lib/rubygems/command.rb126
1 files changed, 81 insertions, 45 deletions
diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb
index 49253ef56b..69cbf3c269 100644
--- a/lib/rubygems/command.rb
+++ b/lib/rubygems/command.rb
@@ -9,7 +9,7 @@ require 'rubygems/user_interaction'
##
# Base class for all Gem commands. When creating a new gem command, define
-# #new, #execute, #arguments, #defaults_str, #description and #usage
+# #initialize, #execute, #arguments, #defaults_str, #description and #usage
# (as appropriate). See the above mentioned methods for details.
#
# A very good example to look at is Gem::Commands::ContentsCommand
@@ -150,8 +150,9 @@ class Gem::Command
def show_lookup_failure(gem_name, version, errors, domain)
if errors and !errors.empty?
- alert_error "Could not find a valid gem '#{gem_name}' (#{version}), here is why:"
- errors.each { |x| say " #{x.wordy}" }
+ msg = "Could not find a valid gem '#{gem_name}' (#{version}), here is why:\n"
+ errors.each { |x| msg << " #{x.wordy}\n" }
+ alert_error msg
else
alert_error "Could not find a valid gem '#{gem_name}' (#{version}) in any repository"
end
@@ -180,6 +181,15 @@ class Gem::Command
end
##
+ # Get all [gem, version] from the command line.
+ #
+ # An argument in the form gem:ver is pull apart into the gen name and version,
+ # respectively.
+ def get_all_gem_names_and_versions
+ get_all_gem_names.map { |name| name.split(":", 2) }
+ end
+
+ ##
# Get a single gem name from the command line. Fail if there is no gem name
# or if there is more than one gem name given.
@@ -268,8 +278,18 @@ class Gem::Command
# Invoke the command with the given list of arguments.
def invoke(*args)
+ invoke_with_build_args args, nil
+ end
+
+ ##
+ # Invoke the command with the given list of normal arguments
+ # and additional build arguments.
+
+ def invoke_with_build_args(args, build_args)
handle_options args
+ options[:build_args] = build_args
+
if options[:help] then
show_help
elsif @when_invoked then
@@ -344,7 +364,7 @@ class Gem::Command
def handle_options(args)
args = add_extra_args(args)
- @options = @defaults.clone
+ @options = Marshal.load Marshal.dump @defaults # deep copy
parser.parse!(args)
@options[:args] = args
end
@@ -372,18 +392,23 @@ class Gem::Command
private
- ##
- # Create on demand parser.
+ def add_parser_description # :nodoc:
+ return unless description
- def parser
- create_option_parser if @parser.nil?
- @parser
- end
+ formatted = description.split("\n\n").map do |chunk|
+ wrap chunk, 80 - 4
+ end.join "\n"
- def create_option_parser
- @parser = OptionParser.new
+ @parser.separator nil
+ @parser.separator " Description:"
+ formatted.split("\n").each do |line|
+ @parser.separator " #{line.rstrip}"
+ end
+ end
+ def add_parser_options # :nodoc:
@parser.separator nil
+
regular_options = @option_groups.delete :options
configure_options "", regular_options
@@ -392,45 +417,56 @@ class Gem::Command
@parser.separator nil
configure_options group_name, option_list
end
+ end
- @parser.separator nil
- configure_options "Common", Gem::Command.common_options
+ ##
+ # Adds a section with +title+ and +content+ to the parser help view. Used
+ # for adding command arguments and default arguments.
- unless arguments.empty?
- @parser.separator nil
- @parser.separator " Arguments:"
- arguments.split(/\n/).each do |arg_desc|
- @parser.separator " #{arg_desc}"
- end
- end
+ def add_parser_run_info title, content
+ return if content.empty?
- if @summary then
- @parser.separator nil
- @parser.separator " Summary:"
- wrap(@summary, 80 - 4).split("\n").each do |line|
- @parser.separator " #{line.strip}"
- end
+ @parser.separator nil
+ @parser.separator " #{title}:"
+ content.split(/\n/).each do |line|
+ @parser.separator " #{line}"
end
+ end
- if description then
- formatted = description.split("\n\n").map do |chunk|
- wrap chunk, 80 - 4
- end.join "\n"
+ def add_parser_summary # :nodoc:
+ return unless @summary
- @parser.separator nil
- @parser.separator " Description:"
- formatted.split("\n").each do |line|
- @parser.separator " #{line.rstrip}"
- end
+ @parser.separator nil
+ @parser.separator " Summary:"
+ wrap(@summary, 80 - 4).split("\n").each do |line|
+ @parser.separator " #{line.strip}"
end
+ end
- unless defaults_str.empty?
- @parser.separator nil
- @parser.separator " Defaults:"
- defaults_str.split(/\n/).each do |line|
- @parser.separator " #{line}"
- end
- end
+ ##
+ # Create on demand parser.
+
+ def parser
+ create_option_parser if @parser.nil?
+ @parser
+ end
+
+ ##
+ # Creates an option parser and fills it in with the help info for the
+ # command.
+
+ def create_option_parser
+ @parser = OptionParser.new
+
+ add_parser_options
+
+ @parser.separator nil
+ configure_options "Common", Gem::Command.common_options
+
+ add_parser_run_info "Arguments", arguments
+ add_parser_summary
+ add_parser_description
+ add_parser_run_info "Defaults", defaults_str
end
def configure_options(header, option_list)
@@ -521,7 +557,7 @@ basic help message containing pointers to more information.
http://localhost:8808/
with info about installed gems
Further information:
- http://rubygems.rubyforge.org
+ http://guides.rubygems.org
HELP
# :startdoc:
@@ -529,7 +565,7 @@ basic help message containing pointers to more information.
end
##
-# This is where Commands will be placed in the namespace
+# \Commands will be placed in this namespace
module Gem::Commands
end