rubygems-update 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (225) hide show
  1. data/ChangeLog +587 -0
  2. data/README +0 -1
  3. data/Rakefile +39 -12
  4. data/TODO +0 -5
  5. data/bin/gem +7 -7
  6. data/bin/update_rubygems +1 -1
  7. data/examples/application/an-app.gemspec +1 -1
  8. data/gemspecs/cgikit-1.1.0.gemspec +1 -2
  9. data/gemspecs/jabber4r.gemspec +1 -1
  10. data/gemspecs/linguistics.gemspec +1 -1
  11. data/gemspecs/ook.gemspec +1 -1
  12. data/gemspecs/progressbar.gemspec +1 -1
  13. data/gemspecs/redcloth.gemspec +1 -1
  14. data/gemspecs/rublog.gemspec +1 -1
  15. data/gemspecs/ruby-doom.gemspec +1 -1
  16. data/gemspecs/rubyjdwp.gemspec +1 -1
  17. data/gemspecs/statistics.gemspec +1 -1
  18. data/lib/rubygems.rb +167 -105
  19. data/lib/rubygems/builder.rb +12 -10
  20. data/lib/rubygems/command.rb +177 -60
  21. data/lib/rubygems/command_manager.rb +30 -38
  22. data/lib/rubygems/commands/build_command.rb +42 -46
  23. data/lib/rubygems/commands/cert_command.rb +72 -69
  24. data/lib/rubygems/commands/check_command.rb +63 -63
  25. data/lib/rubygems/commands/cleanup_command.rb +25 -7
  26. data/lib/rubygems/commands/contents_command.rb +70 -62
  27. data/lib/rubygems/commands/dependency_command.rb +131 -86
  28. data/lib/rubygems/commands/environment_command.rb +67 -46
  29. data/lib/rubygems/commands/fetch_command.rb +62 -0
  30. data/lib/rubygems/commands/generate_index_command.rb +57 -0
  31. data/lib/rubygems/commands/help_command.rb +163 -73
  32. data/lib/rubygems/commands/install_command.rb +114 -128
  33. data/lib/rubygems/commands/list_command.rb +10 -8
  34. data/lib/rubygems/commands/lock_command.rb +101 -0
  35. data/lib/rubygems/commands/mirror_command.rb +105 -0
  36. data/lib/rubygems/commands/outdated_command.rb +24 -15
  37. data/lib/rubygems/commands/pristine_command.rb +118 -88
  38. data/lib/rubygems/commands/query_command.rb +109 -77
  39. data/lib/rubygems/commands/rdoc_command.rb +13 -10
  40. data/lib/rubygems/commands/search_command.rb +10 -8
  41. data/lib/rubygems/commands/server_command.rb +48 -0
  42. data/lib/rubygems/commands/sources_command.rb +104 -83
  43. data/lib/rubygems/commands/specification_command.rb +65 -51
  44. data/lib/rubygems/commands/uninstall_command.rb +17 -12
  45. data/lib/rubygems/commands/unpack_command.rb +68 -68
  46. data/lib/rubygems/commands/update_command.rb +72 -25
  47. data/lib/rubygems/commands/which_command.rb +86 -0
  48. data/lib/rubygems/config_file.rb +202 -78
  49. data/lib/rubygems/custom_require.rb +7 -88
  50. data/lib/rubygems/dependency.rb +65 -0
  51. data/lib/rubygems/dependency_installer.rb +232 -0
  52. data/lib/rubygems/dependency_list.rb +133 -105
  53. data/lib/rubygems/digest/md5.rb +4 -1
  54. data/lib/rubygems/digest/sha2.rb +1 -1
  55. data/lib/rubygems/doc_manager.rb +41 -19
  56. data/lib/rubygems/exceptions.rb +63 -0
  57. data/lib/rubygems/ext.rb +18 -0
  58. data/lib/rubygems/ext/builder.rb +56 -0
  59. data/lib/rubygems/ext/configure_builder.rb +24 -0
  60. data/lib/rubygems/ext/ext_conf_builder.rb +23 -0
  61. data/lib/rubygems/ext/rake_builder.rb +27 -0
  62. data/lib/rubygems/format.rb +16 -6
  63. data/lib/rubygems/gem_openssl.rb +43 -6
  64. data/lib/rubygems/gem_path_searcher.rb +84 -0
  65. data/lib/rubygems/gem_runner.rb +20 -5
  66. data/lib/rubygems/indexer.rb +163 -0
  67. data/lib/rubygems/indexer/abstract_index_builder.rb +80 -0
  68. data/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
  69. data/lib/rubygems/indexer/master_index_builder.rb +53 -0
  70. data/lib/rubygems/indexer/quick_index_builder.rb +48 -0
  71. data/lib/rubygems/install_update_options.rb +87 -0
  72. data/lib/rubygems/installer.rb +316 -562
  73. data/lib/rubygems/local_remote_options.rb +106 -0
  74. data/lib/rubygems/old_format.rb +5 -13
  75. data/lib/rubygems/open-uri.rb +2 -0
  76. data/lib/rubygems/package.rb +28 -32
  77. data/lib/rubygems/platform.rb +187 -0
  78. data/lib/rubygems/remote_fetcher.rb +46 -29
  79. data/lib/rubygems/remote_installer.rb +11 -18
  80. data/lib/rubygems/requirement.rb +157 -0
  81. data/lib/rubygems/rubygems_version.rb +1 -1
  82. data/lib/rubygems/security.rb +715 -457
  83. data/lib/rubygems/server.rb +77 -59
  84. data/lib/rubygems/source_index.rb +154 -83
  85. data/lib/rubygems/source_info_cache.rb +73 -30
  86. data/lib/rubygems/source_info_cache_entry.rb +12 -3
  87. data/lib/rubygems/specification.rb +378 -145
  88. data/lib/rubygems/uninstaller.rb +183 -0
  89. data/lib/rubygems/user_interaction.rb +38 -9
  90. data/lib/rubygems/validator.rb +53 -24
  91. data/lib/rubygems/version.rb +126 -289
  92. data/lib/rubygems/version_option.rb +49 -0
  93. data/pkgs/sources/lib/sources.rb +1 -4
  94. data/pkgs/sources/sources.gemspec +3 -3
  95. data/scripts/gemdoc.rb +0 -1
  96. data/setup.rb +166 -1505
  97. data/test/bogussources.rb +0 -1
  98. data/test/data/gem-private_key.pem +27 -0
  99. data/test/data/gem-public_cert.pem +20 -0
  100. data/test/functional.rb +3 -105
  101. data/test/gemutilities.rb +145 -24
  102. data/test/insure_session.rb +0 -1
  103. data/test/{test_datadir.rb → test_config.rb} +7 -13
  104. data/test/test_gem.rb +360 -9
  105. data/test/test_gem_builder.rb +34 -0
  106. data/test/{test_command.rb → test_gem_command.rb} +119 -62
  107. data/test/{test_parse_commands.rb → test_gem_command_manager.rb} +64 -40
  108. data/test/test_gem_commands_build_command.rb +75 -0
  109. data/test/test_gem_commands_cert_command.rb +122 -0
  110. data/test/test_gem_commands_check_command.rb +25 -0
  111. data/test/test_gem_commands_contents_command.rb +92 -0
  112. data/test/test_gem_commands_dependency_command.rb +108 -0
  113. data/test/test_gem_commands_environment_command.rb +117 -0
  114. data/test/test_gem_commands_fetch_command.rb +34 -0
  115. data/test/test_gem_commands_generate_index_command.rb +32 -0
  116. data/test/test_gem_commands_install_command.rb +160 -0
  117. data/test/test_gem_commands_mirror_command.rb +56 -0
  118. data/test/test_gem_commands_pristine_command.rb +100 -0
  119. data/test/test_gem_commands_query_command.rb +82 -0
  120. data/test/test_gem_commands_sources_command.rb +147 -0
  121. data/test/test_gem_commands_specification_command.rb +93 -0
  122. data/test/test_gem_commands_unpack_command.rb +55 -0
  123. data/test/test_gem_config_file.rb +210 -0
  124. data/test/test_gem_dependency.rb +89 -0
  125. data/test/test_gem_dependency_installer.rb +542 -0
  126. data/test/test_gem_dependency_list.rb +212 -0
  127. data/test/test_gem_doc_manager.rb +32 -0
  128. data/test/test_gem_ext_configure_builder.rb +13 -17
  129. data/test/test_gem_ext_ext_conf_builder.rb +9 -9
  130. data/test/test_gem_ext_rake_builder.rb +23 -11
  131. data/test/test_gem_format.rb +69 -0
  132. data/test/test_gem_gem_path_searcher.rb +57 -0
  133. data/test/test_gem_gem_runner.rb +35 -0
  134. data/test/test_gem_indexer.rb +119 -0
  135. data/test/test_gem_install_update_options.rb +40 -0
  136. data/test/test_gem_installer.rb +796 -0
  137. data/test/test_gem_local_remote_options.rb +84 -0
  138. data/test/test_gem_outdated_command.rb +11 -9
  139. data/test/test_gem_platform.rb +240 -0
  140. data/test/{test_remote_fetcher.rb → test_gem_remote_fetcher.rb} +124 -55
  141. data/test/{test_remote_installer.rb → test_gem_remote_installer.rb} +3 -4
  142. data/test/test_gem_requirement.rb +223 -0
  143. data/test/test_gem_server.rb +71 -0
  144. data/test/test_gem_source_index.rb +429 -0
  145. data/test/test_gem_source_info_cache.rb +79 -17
  146. data/test/test_gem_source_info_cache_entry.rb +11 -9
  147. data/test/test_gem_specification.rb +738 -0
  148. data/test/test_gem_stream_ui.rb +117 -0
  149. data/test/test_gem_validator.rb +70 -0
  150. data/test/test_gem_version.rb +191 -0
  151. data/test/test_gem_version_option.rb +77 -0
  152. data/test/{test_require_gem.rb → test_kernel.rb} +19 -12
  153. data/test/test_open_uri.rb +1 -2
  154. data/test/test_package.rb +45 -34
  155. metadata +116 -141
  156. data/Releases +0 -127
  157. data/bin/gem_mirror +0 -73
  158. data/bin/gem_server +0 -6
  159. data/bin/gemlock +0 -127
  160. data/bin/gemri +0 -24
  161. data/bin/gemwhich +0 -89
  162. data/bin/index_gem_repository.rb +0 -302
  163. data/lib/gemconfigure.rb +0 -24
  164. data/lib/rubygems/gem_commands.rb +0 -273
  165. data/pkgs/sources/sources-0.0.1.gem +0 -0
  166. data/post-install.rb +0 -121
  167. data/test/brokenbuildgem.rb +0 -35
  168. data/test/data/PostMessage-0.0.1.gem +0 -0
  169. data/test/data/a-0.0.1.gem +0 -0
  170. data/test/data/a-0.0.2.gem +0 -0
  171. data/test/data/b-0.0.2.gem +0 -0
  172. data/test/data/broken-1.0.0.gem +0 -0
  173. data/test/data/broken_build/broken-build.gemspec +0 -20
  174. data/test/data/broken_build/ext/extconf.rb +0 -3
  175. data/test/data/broken_build/ext/foo.c +0 -1
  176. data/test/data/c-1.2.gem +0 -0
  177. data/test/data/gemhome/cache/a-0.0.1.gem +0 -0
  178. data/test/data/gemhome/cache/a-0.0.2.gem +0 -0
  179. data/test/data/gemhome/cache/b-0.0.2.gem +0 -0
  180. data/test/data/gemhome/cache/c-1.2.gem +0 -0
  181. data/test/data/gemhome/gems/a-0.0.1/lib/code.rb +0 -1
  182. data/test/data/gemhome/gems/a-0.0.2/lib/code.rb +0 -1
  183. data/test/data/gemhome/gems/b-0.0.2/lib/code.rb +0 -1
  184. data/test/data/gemhome/gems/c-1.2/lib/code.rb +0 -1
  185. data/test/data/gemhome/specifications/a-0.0.1.gemspec +0 -8
  186. data/test/data/gemhome/specifications/a-0.0.2.gemspec +0 -8
  187. data/test/data/gemhome/specifications/b-0.0.2.gemspec +0 -8
  188. data/test/data/gemhome/specifications/c-1.2.gemspec +0 -8
  189. data/test/data/legacy/keyedlist-0.4.0.ruby +0 -11
  190. data/test/data/legacy/keyedlist-0.4.0.yaml +0 -16
  191. data/test/data/lib/code.rb +0 -1
  192. data/test/data/one/README.one +0 -1
  193. data/test/data/one/lib/one.rb +0 -9
  194. data/test/data/one/one-0.0.1.gem +0 -0
  195. data/test/data/one/one.gemspec +0 -17
  196. data/test/data/one/one.yaml +0 -40
  197. data/test/data/post_install.gemspec +0 -19
  198. data/test/functional_extension_gems.rb +0 -48
  199. data/test/functional_generate_yaml_index.rb +0 -104
  200. data/test/gemenvironment.rb +0 -59
  201. data/test/io_capture.rb +0 -33
  202. data/test/mock/gems/gems/sources-0.0.1/lib/sources.rb +0 -11
  203. data/test/mock/gems/specifications/sources-0.0.1.gemspec +0 -8
  204. data/test/onegem.rb +0 -35
  205. data/test/test_builder.rb +0 -34
  206. data/test/test_check_command.rb +0 -34
  207. data/test/test_configfile.rb +0 -42
  208. data/test/test_dependency_list.rb +0 -169
  209. data/test/test_file_list.rb +0 -101
  210. data/test/test_format.rb +0 -49
  211. data/test/test_gem_sources_command.rb +0 -135
  212. data/test/test_gemloadpaths.rb +0 -51
  213. data/test/test_gempaths.rb +0 -170
  214. data/test/test_installer.rb +0 -369
  215. data/test/test_loadmanager.rb +0 -48
  216. data/test/test_process_commands.rb +0 -52
  217. data/test/test_source_index.rb +0 -231
  218. data/test/test_specific_extras.rb +0 -46
  219. data/test/test_specification.rb +0 -565
  220. data/test/test_user_interaction.rb +0 -48
  221. data/test/test_validator.rb +0 -59
  222. data/test/test_version_comparison.rb +0 -321
  223. data/test/testgem.rc +0 -7
  224. data/test/user_capture.rb +0 -7
  225. data/test/yaml_data.rb +0 -63
@@ -4,11 +4,6 @@
4
4
  # See LICENSE.txt for permissions.
5
5
  #++
6
6
 
7
- require "rubygems/package"
8
- require "rubygems/security"
9
- require "yaml"
10
- require 'rubygems/gem_openssl'
11
-
12
7
  module Gem
13
8
 
14
9
  ##
@@ -24,11 +19,16 @@ module Gem
24
19
  # spec:: [Gem::Specification] The specification instance
25
20
  #
26
21
  def initialize(spec)
22
+ require "yaml"
23
+ require "rubygems/package"
24
+ require "rubygems/security"
25
+
27
26
  @spec = spec
28
27
  end
29
-
28
+
30
29
  ##
31
- # Builds the gem from the specification. Returns the name of the file written.
30
+ # Builds the gem from the specification. Returns the name of the file
31
+ # written.
32
32
  #
33
33
  def build
34
34
  @spec.mark_version
@@ -47,13 +47,14 @@ module Gem
47
47
  File: #{@spec.full_name+'.gem'}
48
48
  EOM
49
49
  end
50
-
50
+
51
51
  private
52
+
52
53
  def sign
53
54
  # if the signing key was specified, then load the file, and swap
54
55
  # to the public key (TODO: we should probably just omit the
55
56
  # signing key in favor of the signing certificate, but that's for
56
- # the future, also the signature algorihtm should be configurable)
57
+ # the future, also the signature algorithm should be configurable)
57
58
  signer = nil
58
59
  if @spec.respond_to?(:signing_key) && @spec.signing_key
59
60
  signer = Gem::Security::Signer.new(@spec.signing_key, @spec.cert_chain)
@@ -62,7 +63,7 @@ EOM
62
63
  end
63
64
  signer
64
65
  end
65
-
66
+
66
67
  def write_package
67
68
  Package.open(@spec.file_name, "w", @signer) do |pkg|
68
69
  pkg.metadata = @spec.to_yaml
@@ -77,3 +78,4 @@ EOM
77
78
  end
78
79
  end
79
80
  end
81
+
@@ -4,40 +4,96 @@
4
4
  # See LICENSE.txt for permissions.
5
5
  #++
6
6
 
7
+ require 'optparse'
8
+
7
9
  require 'rubygems/user_interaction'
8
10
 
9
11
  module Gem
10
12
 
11
- ####################################################################
12
- # Base class for all Gem commands.
13
+ # Base class for all Gem commands. When creating a new gem command, define
14
+ # #arguments, #defaults_str, #description and #usage (as appropriate).
13
15
  class Command
16
+
14
17
  include UserInteraction
15
-
16
- Option = Struct.new(:short, :long, :description, :handler)
17
-
18
- attr_reader :command, :options
19
- attr_accessor :summary, :defaults, :program_name
20
-
21
- # Initialize a generic gem command.
18
+
19
+ # The name of the command.
20
+ attr_reader :command
21
+
22
+ # The options for the command.
23
+ attr_reader :options
24
+
25
+ # The default options for the command.
26
+ attr_accessor :defaults
27
+
28
+ # The name of the command for command-line invocation.
29
+ attr_accessor :program_name
30
+
31
+ # A short description of the command.
32
+ attr_accessor :summary
33
+
34
+ # Initializes a generic gem command named +command+. +summary+ is a short
35
+ # description displayed in `gem help commands`. +defaults+ are the
36
+ # default options. Defaults should be mirrored in #defaults_str, unless
37
+ # there are none.
38
+ #
39
+ # Use add_option to add command-line switches.
22
40
  def initialize(command, summary=nil, defaults={})
23
41
  @command = command
24
42
  @summary = summary
25
43
  @program_name = "gem #{command}"
26
44
  @defaults = defaults
27
45
  @options = defaults.dup
28
- @option_list = []
46
+ @option_groups = Hash.new { |h,k| h[k] = [] }
29
47
  @parser = nil
30
48
  @when_invoked = nil
31
49
  end
32
-
50
+
51
+ # True if +long+ begins with the characters from +short+.
52
+ def begins?(long, short)
53
+ return false if short.nil?
54
+ long[0, short.length] == short
55
+ end
56
+
33
57
  # Override to provide command handling.
34
58
  def execute
35
59
  fail "Generic command has no actions"
36
60
  end
37
61
 
38
- # Override to display the usage for an individual gem command.
39
- def usage
40
- program_name
62
+ # Get all gem names from the command line.
63
+ def get_all_gem_names
64
+ args = options[:args]
65
+
66
+ if args.nil? or args.empty? then
67
+ raise Gem::CommandLineError,
68
+ "Please specify at least one gem name (e.g. gem build GEMNAME)"
69
+ end
70
+
71
+ gem_names = args.select { |arg| arg !~ /^-/ }
72
+ end
73
+
74
+ # Get the single gem name from the command line. Fail if there is no gem
75
+ # name or if there is more than one gem name given.
76
+ def get_one_gem_name
77
+ args = options[:args]
78
+
79
+ if args.nil? or args.empty? then
80
+ raise Gem::CommandLineError,
81
+ "Please specify a gem name on the command line (e.g. gem build GEMNAME)"
82
+ end
83
+
84
+ if args.size > 1 then
85
+ raise Gem::CommandLineError,
86
+ "Too many gem names (#{args.join(', ')}); please specify only one"
87
+ end
88
+
89
+ args.first
90
+ end
91
+
92
+ # Get a single optional argument from the command line. If more than one
93
+ # argument is given, return only the first. Return nil if none are given.
94
+ def get_one_optional_argument
95
+ args = options[:args] || []
96
+ args.first
41
97
  end
42
98
 
43
99
  # Override to provide details of the arguments a command takes.
@@ -53,7 +109,17 @@ module Gem
53
109
  ""
54
110
  end
55
111
 
56
- # Display the help message for this command.
112
+ # Override to display a longer description of what this command does.
113
+ def description
114
+ nil
115
+ end
116
+
117
+ # Override to display the usage for an individual gem command.
118
+ def usage
119
+ program_name
120
+ end
121
+
122
+ # Display the help message for the command.
57
123
  def show_help
58
124
  parser.program_name = usage
59
125
  say parser
@@ -81,14 +147,23 @@ module Gem
81
147
  @when_invoked = block
82
148
  end
83
149
 
84
- # Add a option (and a handler) to this command.
85
- def add_option(*args, &handler)
86
- @option_list << [args, handler]
150
+ # Add a command-line option and handler to the command.
151
+ #
152
+ # See OptionParser#make_switch for an explanation of +opts+.
153
+ #
154
+ # +handler+ will be called with two values, the value of the argument and
155
+ # the options hash.
156
+ def add_option(*opts, &handler) # :yields: value, options
157
+ group_name = Symbol === opts.first ? opts.shift : :options
158
+
159
+ @option_groups[group_name] << [opts, handler]
87
160
  end
88
161
 
89
- # Remove a previously defined command option.
162
+ # Remove previously defined command-line argument +name+.
90
163
  def remove_option(name)
91
- @option_list.reject! { |args, handler| args.any? { |x| x =~ /^#{name}/ } }
164
+ @option_groups.each do |_, option_list|
165
+ option_list.reject! { |args, _| args.any? { |x| x =~ /^#{name}/ } }
166
+ end
92
167
  end
93
168
 
94
169
  # Merge a set of command options with the set of default options
@@ -108,13 +183,6 @@ module Gem
108
183
  end
109
184
  end
110
185
 
111
- private
112
-
113
- # Return the command manager instance.
114
- def command_manager
115
- Gem::CommandManager.instance
116
- end
117
-
118
186
  # Handle the given list of arguments by parsing them and recording
119
187
  # the results.
120
188
  def handle_options(args)
@@ -138,7 +206,9 @@ module Gem
138
206
  result.concat(args)
139
207
  result
140
208
  end
141
-
209
+
210
+ private
211
+
142
212
  # Create on demand parser.
143
213
  def parser
144
214
  create_option_parser if @parser.nil?
@@ -146,17 +216,19 @@ module Gem
146
216
  end
147
217
 
148
218
  def create_option_parser
149
- require 'optparse'
150
219
  @parser = OptionParser.new
151
- option_names = {}
220
+
152
221
  @parser.separator("")
153
- unless @option_list.empty?
154
- @parser.separator(" Options:")
155
- configure_options(@option_list, option_names)
156
- @parser.separator("")
222
+ regular_options = @option_groups.delete :options
223
+
224
+ configure_options "", regular_options
225
+
226
+ @option_groups.sort_by { |n,_| n.to_s }.each do |group_name, option_list|
227
+ configure_options group_name, option_list
157
228
  end
158
- @parser.separator(" Common Options:")
159
- configure_options(Command.common_options, option_names)
229
+
230
+ configure_options "Common", Command.common_options
231
+
160
232
  @parser.separator("")
161
233
  unless arguments.empty?
162
234
  @parser.separator(" Arguments:")
@@ -165,10 +237,24 @@ module Gem
165
237
  end
166
238
  @parser.separator("")
167
239
  end
240
+
168
241
  @parser.separator(" Summary:")
169
- wrap(@summary, 80 - 4).each do |line|
242
+ wrap(@summary, 80 - 4).split("\n").each do |line|
170
243
  @parser.separator(" #{line.strip}")
171
244
  end
245
+
246
+ if description then
247
+ formatted = description.split("\n\n").map do |chunk|
248
+ wrap(chunk, 80 - 4)
249
+ end.join("\n")
250
+
251
+ @parser.separator ""
252
+ @parser.separator " Description:"
253
+ formatted.split("\n").each do |line|
254
+ @parser.separator " #{line.rstrip}"
255
+ end
256
+ end
257
+
172
258
  unless defaults_str.empty?
173
259
  @parser.separator("")
174
260
  @parser.separator(" Defaults:")
@@ -178,15 +264,20 @@ module Gem
178
264
  end
179
265
  end
180
266
 
181
- def configure_options(option_list, option_names)
267
+ def configure_options(header, option_list)
268
+ return if option_list.nil? or option_list.empty?
269
+
270
+ header = header.to_s.empty? ? '' : "#{header} "
271
+ @parser.separator " #{header}Options:"
272
+
182
273
  option_list.each do |args, handler|
183
274
  dashes = args.select { |arg| arg =~ /^-/ }
184
- next if dashes.any? { |arg| option_names[arg] }
185
275
  @parser.on(*args) do |value|
186
276
  handler.call(value, @options)
187
277
  end
188
- dashes.each do |arg| option_names[arg] = true end
189
278
  end
279
+
280
+ @parser.separator ''
190
281
  end
191
282
 
192
283
  # Wraps +text+ to +width+
@@ -242,21 +333,6 @@ module Gem
242
333
 
243
334
  # ----------------------------------------------------------------
244
335
  # Add the options common to all commands.
245
-
246
- add_common_option('--source URL',
247
- 'Use URL as the remote source for gems') do
248
- |value, options|
249
- gem("sources")
250
- Gem.sources.clear
251
- Gem.sources << value
252
- end
253
-
254
- add_common_option('-p', '--[no-]http-proxy [URL]',
255
- 'Use HTTP proxy for remote operations') do
256
- |value, options|
257
- options[:http_proxy] = (value == false) ? :no_proxy : value
258
- Gem.configuration[:http_proxy] = options[:http_proxy]
259
- end
260
336
 
261
337
  add_common_option('-h', '--help',
262
338
  'Get help on this command') do
@@ -264,10 +340,18 @@ module Gem
264
340
  options[:help] = true
265
341
  end
266
342
 
267
- add_common_option('-v', '--verbose',
268
- 'Set the verbose level of output') do
269
- |value, options|
270
- Gem.configuration.verbose = value
343
+ add_common_option('-V', '--[no-]verbose',
344
+ 'Set the verbose level of output') do |value, options|
345
+ # Set us to "really verbose" so the progess meter works
346
+ if Gem.configuration.verbose and value then
347
+ Gem.configuration.verbose = 1
348
+ else
349
+ Gem.configuration.verbose = value
350
+ end
351
+ end
352
+
353
+ add_common_option('-q', '--quiet', 'Silence commands') do |value, options|
354
+ Gem.configuration.verbose = false
271
355
  end
272
356
 
273
357
  # Backtrace and config-file are added so they show up in the help
@@ -285,5 +369,38 @@ module Gem
285
369
  add_common_option('--debug',
286
370
  'Turn on Ruby debugging') do
287
371
  end
372
+
373
+ # :stopdoc:
374
+ HELP = %{
375
+ RubyGems is a sophisticated package manager for Ruby. This is a
376
+ basic help message containing pointers to more information.
377
+
378
+ Usage:
379
+ gem -h/--help
380
+ gem -v/--version
381
+ gem command [arguments...] [options...]
382
+
383
+ Examples:
384
+ gem install rake
385
+ gem list --local
386
+ gem build package.gemspec
387
+ gem help install
388
+
389
+ Further help:
390
+ gem help commands list all 'gem' commands
391
+ gem help examples show some examples of usage
392
+ gem help platforms show information about platforms
393
+ gem help <COMMAND> show help on COMMAND
394
+ (e.g. 'gem help install')
395
+ Further information:
396
+ http://rubygems.rubyforge.org
397
+ }.gsub(/^ /, "")
398
+
399
+ # :startdoc:
400
+
288
401
  end # class
289
- end # module
402
+
403
+ # This is where Commands will be placed in the namespace
404
+ module Commands; end
405
+
406
+ end
@@ -4,43 +4,17 @@
4
4
  # See LICENSE.txt for permissions.
5
5
  #++
6
6
 
7
- require 'rubygems'
7
+ require 'timeout'
8
8
  require 'rubygems/command'
9
9
  require 'rubygems/user_interaction'
10
- require 'rubygems/gem_commands'
11
- require 'timeout'
12
10
 
13
11
  module Gem
14
12
 
15
- ###################################################################
16
- # Signals that local installation will not proceed, not that it has
17
- # been tried and failed. TODO: better name.
18
- class LocalInstallationError < Gem::Exception; end
19
-
20
- ####################################################################
21
- # Signals that a file permission error is preventing the user from
22
- # installing in the requested directories.
23
- class FilePermissionError < Gem::Exception
24
- def initialize(path)
25
- super("You don't have write permissions into the #{path} directory.")
26
- end
27
- end
28
-
29
- ####################################################################
30
- # Signals that a remote operation cannot be conducted, probably due
31
- # to not being connected (or just not finding host).
32
- #
33
- # TODO: create a method that tests connection to the preferred gems
34
- # server. All code dealing with remote operations will want this.
35
- # Failure in that method should raise this error.
36
- class RemoteError < Gem::Exception; end
37
-
38
13
  ####################################################################
39
14
  # The command manager registers and installs all the individual
40
15
  # sub-commands supported by the gem command.
41
16
  class CommandManager
42
17
  include UserInteraction
43
- include Commands
44
18
 
45
19
  # Return the authoratative instance of the command manager.
46
20
  def self.instance
@@ -53,33 +27,41 @@ module Gem
53
27
  register_command :build
54
28
  register_command :cert
55
29
  register_command :check
30
+ register_command :cleanup
56
31
  register_command :contents
57
32
  register_command :dependency
58
33
  register_command :environment
34
+ register_command :fetch
35
+ register_command :generate_index
59
36
  register_command :help
60
37
  register_command :install
38
+ register_command :list
39
+ register_command :lock
40
+ register_command :mirror
61
41
  register_command :outdated
62
42
  register_command :pristine
63
43
  register_command :query
64
- register_command :list
65
44
  register_command :rdoc
66
45
  register_command :search
46
+ register_command :server
67
47
  register_command :sources
68
48
  register_command :specification
69
49
  register_command :uninstall
70
50
  register_command :unpack
71
- register_command :cleanup
72
51
  register_command :update
52
+ register_command :which
73
53
  end
74
54
 
75
55
  # Register the command object.
76
56
  def register_command(command_obj)
77
- @commands[command_obj] = load_and_instantiate(command_obj)
57
+ @commands[command_obj] = false
78
58
  end
79
59
 
80
60
  # Return the registered command from the command name.
81
61
  def [](command_name)
82
- @commands[command_name.intern]
62
+ command_name = command_name.intern
63
+ return nil if @commands[command_name].nil?
64
+ @commands[command_name] ||= load_and_instantiate(command_name)
83
65
  end
84
66
 
85
67
  # Return a list of all command names (as strings).
@@ -92,7 +74,8 @@ module Gem
92
74
  process_args(args)
93
75
  rescue StandardError, Timeout::Error => ex
94
76
  alert_error "While executing gem ... (#{ex.class})\n #{ex.to_s}"
95
- puts ex.backtrace if Gem.configuration.backtrace
77
+ ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
78
+ Gem.configuration.backtrace
96
79
  terminate_interaction(1)
97
80
  rescue Interrupt
98
81
  alert_error "Interrupted"
@@ -102,12 +85,12 @@ module Gem
102
85
  def process_args(args)
103
86
  args = args.to_str.split(/\s+/) if args.respond_to?(:to_str)
104
87
  if args.size == 0
105
- say Gem::HELP
88
+ say Gem::Command::HELP
106
89
  terminate_interaction(1)
107
90
  end
108
91
  case args[0]
109
92
  when '-h', '--help'
110
- say Gem::HELP
93
+ say Gem::Command::HELP
111
94
  terminate_interaction(0)
112
95
  when '-v', '--version'
113
96
  say Gem::RubyGemsPackageVersion
@@ -130,6 +113,7 @@ module Gem
130
113
  if possibilities.size < 1
131
114
  raise "Unknown command #{cmd_name}"
132
115
  end
116
+
133
117
  self[possibilities.first]
134
118
  end
135
119
 
@@ -141,11 +125,19 @@ module Gem
141
125
  private
142
126
  def load_and_instantiate(command_name)
143
127
  command_name = command_name.to_s
128
+ retried = false
129
+
144
130
  begin
145
- Gem::Commands.const_get("#{command_name.capitalize}Command").new
146
- rescue
147
- require "rubygems/commands/#{command_name}_command"
148
- retry
131
+ const_name = command_name.capitalize.gsub(/_(.)/) { $1.upcase }
132
+ Gem::Commands.const_get("#{const_name}Command").new
133
+ rescue NameError
134
+ if retried then
135
+ raise
136
+ else
137
+ retried = true
138
+ require "rubygems/commands/#{command_name}_command"
139
+ retry
140
+ end
149
141
  end
150
142
  end
151
143
  end