honkster-bundler 1.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. data/.gitignore +14 -0
  2. data/CHANGELOG.md +547 -0
  3. data/ISSUES.md +32 -0
  4. data/LICENSE +20 -0
  5. data/README.md +29 -0
  6. data/Rakefile +150 -0
  7. data/UPGRADING.md +103 -0
  8. data/bin/bundle +21 -0
  9. data/bundler.gemspec +30 -0
  10. data/lib/bundler.rb +268 -0
  11. data/lib/bundler/capistrano.rb +11 -0
  12. data/lib/bundler/cli.rb +515 -0
  13. data/lib/bundler/definition.rb +427 -0
  14. data/lib/bundler/dependency.rb +114 -0
  15. data/lib/bundler/deployment.rb +37 -0
  16. data/lib/bundler/dsl.rb +245 -0
  17. data/lib/bundler/environment.rb +47 -0
  18. data/lib/bundler/gem_helper.rb +145 -0
  19. data/lib/bundler/graph.rb +130 -0
  20. data/lib/bundler/index.rb +114 -0
  21. data/lib/bundler/installer.rb +84 -0
  22. data/lib/bundler/lazy_specification.rb +71 -0
  23. data/lib/bundler/lockfile_parser.rb +108 -0
  24. data/lib/bundler/remote_specification.rb +59 -0
  25. data/lib/bundler/resolver.rb +454 -0
  26. data/lib/bundler/rubygems_ext.rb +203 -0
  27. data/lib/bundler/runtime.rb +148 -0
  28. data/lib/bundler/settings.rb +117 -0
  29. data/lib/bundler/setup.rb +15 -0
  30. data/lib/bundler/shared_helpers.rb +151 -0
  31. data/lib/bundler/source.rb +662 -0
  32. data/lib/bundler/spec_set.rb +134 -0
  33. data/lib/bundler/templates/Executable +16 -0
  34. data/lib/bundler/templates/Gemfile +4 -0
  35. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  36. data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
  37. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  38. data/lib/bundler/templates/newgem/gitignore.tt +3 -0
  39. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +7 -0
  40. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  41. data/lib/bundler/templates/newgem/newgem.gemspec.tt +21 -0
  42. data/lib/bundler/ui.rb +60 -0
  43. data/lib/bundler/vendor/thor.rb +319 -0
  44. data/lib/bundler/vendor/thor/actions.rb +297 -0
  45. data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
  46. data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
  47. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  48. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +229 -0
  49. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +104 -0
  50. data/lib/bundler/vendor/thor/base.rb +556 -0
  51. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  52. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  53. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  54. data/lib/bundler/vendor/thor/error.rb +30 -0
  55. data/lib/bundler/vendor/thor/invocation.rb +168 -0
  56. data/lib/bundler/vendor/thor/parser.rb +4 -0
  57. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  58. data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
  59. data/lib/bundler/vendor/thor/parser/option.rb +120 -0
  60. data/lib/bundler/vendor/thor/parser/options.rb +174 -0
  61. data/lib/bundler/vendor/thor/shell.rb +88 -0
  62. data/lib/bundler/vendor/thor/shell/basic.rb +275 -0
  63. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  64. data/lib/bundler/vendor/thor/shell/html.rb +121 -0
  65. data/lib/bundler/vendor/thor/task.rb +114 -0
  66. data/lib/bundler/vendor/thor/util.rb +229 -0
  67. data/lib/bundler/vendor/thor/version.rb +3 -0
  68. data/lib/bundler/version.rb +6 -0
  69. data/lib/bundler/vlad.rb +9 -0
  70. data/man/bundle-config.ronn +90 -0
  71. data/man/bundle-exec.ronn +98 -0
  72. data/man/bundle-install.ronn +310 -0
  73. data/man/bundle-package.ronn +59 -0
  74. data/man/bundle-update.ronn +176 -0
  75. data/man/bundle.ronn +77 -0
  76. data/man/gemfile.5.ronn +273 -0
  77. data/man/index.txt +6 -0
  78. data/spec/cache/gems_spec.rb +205 -0
  79. data/spec/cache/git_spec.rb +9 -0
  80. data/spec/cache/path_spec.rb +27 -0
  81. data/spec/cache/platform_spec.rb +57 -0
  82. data/spec/install/deploy_spec.rb +197 -0
  83. data/spec/install/deprecated_spec.rb +43 -0
  84. data/spec/install/gems/c_ext_spec.rb +48 -0
  85. data/spec/install/gems/env_spec.rb +107 -0
  86. data/spec/install/gems/flex_spec.rb +272 -0
  87. data/spec/install/gems/groups_spec.rb +228 -0
  88. data/spec/install/gems/packed_spec.rb +72 -0
  89. data/spec/install/gems/platform_spec.rb +195 -0
  90. data/spec/install/gems/resolving_spec.rb +72 -0
  91. data/spec/install/gems/simple_case_spec.rb +749 -0
  92. data/spec/install/gems/sudo_spec.rb +77 -0
  93. data/spec/install/gems/win32_spec.rb +26 -0
  94. data/spec/install/gemspec_spec.rb +96 -0
  95. data/spec/install/git_spec.rb +553 -0
  96. data/spec/install/invalid_spec.rb +17 -0
  97. data/spec/install/path_spec.rb +329 -0
  98. data/spec/install/upgrade_spec.rb +26 -0
  99. data/spec/lock/flex_spec.rb +650 -0
  100. data/spec/lock/git_spec.rb +35 -0
  101. data/spec/other/check_spec.rb +221 -0
  102. data/spec/other/config_spec.rb +40 -0
  103. data/spec/other/console_spec.rb +54 -0
  104. data/spec/other/exec_spec.rb +241 -0
  105. data/spec/other/ext_spec.rb +16 -0
  106. data/spec/other/gem_helper_spec.rb +126 -0
  107. data/spec/other/help_spec.rb +36 -0
  108. data/spec/other/init_spec.rb +40 -0
  109. data/spec/other/newgem_spec.rb +24 -0
  110. data/spec/other/open_spec.rb +35 -0
  111. data/spec/other/show_spec.rb +82 -0
  112. data/spec/pack/gems_spec.rb +22 -0
  113. data/spec/quality_spec.rb +55 -0
  114. data/spec/resolver/basic_spec.rb +20 -0
  115. data/spec/resolver/platform_spec.rb +57 -0
  116. data/spec/runtime/environment_rb_spec.rb +162 -0
  117. data/spec/runtime/executable_spec.rb +110 -0
  118. data/spec/runtime/load_spec.rb +102 -0
  119. data/spec/runtime/platform_spec.rb +90 -0
  120. data/spec/runtime/require_spec.rb +231 -0
  121. data/spec/runtime/setup_spec.rb +412 -0
  122. data/spec/runtime/with_clean_env_spec.rb +15 -0
  123. data/spec/spec_helper.rb +82 -0
  124. data/spec/support/builders.rb +566 -0
  125. data/spec/support/helpers.rb +243 -0
  126. data/spec/support/indexes.rb +113 -0
  127. data/spec/support/matchers.rb +89 -0
  128. data/spec/support/path.rb +71 -0
  129. data/spec/support/platforms.rb +49 -0
  130. data/spec/support/ruby_ext.rb +19 -0
  131. data/spec/support/rubygems_ext.rb +30 -0
  132. data/spec/support/rubygems_hax/rubygems_plugin.rb +9 -0
  133. data/spec/support/sudo.rb +21 -0
  134. data/spec/update/gems_spec.rb +112 -0
  135. data/spec/update/git_spec.rb +159 -0
  136. data/spec/update/source_spec.rb +50 -0
  137. metadata +251 -0
@@ -0,0 +1,11 @@
1
+ # Capistrano task for Bundler.
2
+ #
3
+ # Just add "require 'bundler/capistrano'" in your Capistrano deploy.rb, and
4
+ # Bundler will be activated after each new deployment.
5
+ require 'bundler/deployment'
6
+
7
+ Capistrano::Configuration.instance(:must_exist).load do
8
+ after "deploy:update_code", "bundle:install"
9
+
10
+ Bundler::Deployment.define_task(self, :task, :except => { :no_release => true })
11
+ end
@@ -0,0 +1,515 @@
1
+ $:.unshift File.expand_path('../vendor', __FILE__)
2
+ require 'thor'
3
+ require 'thor/actions'
4
+ require 'rubygems/config_file'
5
+
6
+ # Work around a RubyGems bug
7
+ Gem.configuration
8
+
9
+ module Bundler
10
+ class CLI < Thor
11
+ include Thor::Actions
12
+
13
+ def initialize(*)
14
+ super
15
+ use_shell = options["no-color"] ? Thor::Shell::Basic.new : shell
16
+
17
+ Bundler.ui = UI::Shell.new(use_shell)
18
+ Gem::DefaultUserInteraction.ui = UI::RGProxy.new(Bundler.ui)
19
+ end
20
+
21
+ check_unknown_options! unless ARGV.include?("exec") || ARGV.include?("config")
22
+
23
+ default_task :install
24
+ class_option "no-color", :type => :boolean, :banner => "Disable colorization in output"
25
+
26
+ def help(cli = nil)
27
+ case cli
28
+ when "gemfile" then command = "gemfile.5"
29
+ when nil then command = "bundle"
30
+ else command = "bundle-#{cli}"
31
+ end
32
+
33
+ manpages = %w(
34
+ bundle
35
+ bundle-config
36
+ bundle-exec
37
+ bundle-install
38
+ bundle-package
39
+ bundle-update
40
+ gemfile.5)
41
+
42
+ if manpages.include?(command)
43
+ root = File.expand_path("../man", __FILE__)
44
+
45
+ if have_groff? && root !~ %r{^file:/.+!/META-INF/jruby.home/.+}
46
+ groff = "groff -Wall -mtty-char -mandoc -Tascii"
47
+ pager = ENV['MANPAGER'] || ENV['PAGER'] || 'more'
48
+
49
+ Kernel.exec "#{groff} #{root}/#{command} | #{pager}"
50
+ else
51
+ puts File.read("#{root}/#{command}.txt")
52
+ end
53
+ else
54
+ super
55
+ end
56
+ end
57
+
58
+ desc "init", "Generates a Gemfile into the current working directory"
59
+ long_desc <<-D
60
+ Init generates a default Gemfile in the current working directory. When adding a
61
+ Gemfile to a gem with a gemspec, the --gemspec option will automatically add each
62
+ dependency listed in the gemspec file to the newly created Gemfile.
63
+ D
64
+ method_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile"
65
+ def init
66
+ opts = options.dup
67
+ if File.exist?("Gemfile")
68
+ Bundler.ui.error "Gemfile already exists at #{Dir.pwd}/Gemfile"
69
+ exit 1
70
+ end
71
+
72
+ if opts[:gemspec]
73
+ gemspec = File.expand_path(opts[:gemspec])
74
+ unless File.exist?(gemspec)
75
+ Bundler.ui.error "Gem specification #{gemspec} doesn't exist"
76
+ exit 1
77
+ end
78
+ spec = Gem::Specification.load(gemspec)
79
+ puts "Writing new Gemfile to #{Dir.pwd}/Gemfile"
80
+ File.open('Gemfile', 'wb') do |file|
81
+ file << "# Generated from #{gemspec}\n"
82
+ file << spec.to_gemfile
83
+ end
84
+ else
85
+ puts "Writing new Gemfile to #{Dir.pwd}/Gemfile"
86
+ FileUtils.cp(File.expand_path('../templates/Gemfile', __FILE__), 'Gemfile')
87
+ end
88
+ end
89
+
90
+ desc "check", "Checks if the dependencies listed in Gemfile are satisfied by currently installed gems"
91
+ long_desc <<-D
92
+ Check searches the local machine for each of the gems requested in the Gemfile. If
93
+ all gems are found, Bundler prints a success message and exits with a status of 0.
94
+ If not, the first missing gem is listed and Bundler exits status 1.
95
+ D
96
+ method_option "gemfile", :type => :string, :banner =>
97
+ "Use the specified gemfile instead of Gemfile"
98
+ def check
99
+ ENV['BUNDLE_GEMFILE'] = File.expand_path(options[:gemfile]) if options[:gemfile]
100
+ begin
101
+ not_installed = Bundler.definition.missing_specs
102
+ rescue GemNotFound, VersionConflict
103
+ Bundler.ui.error "Your Gemfile's dependencies could not be satisfied"
104
+ Bundler.ui.warn "Install missing gems with `bundle install`"
105
+ exit 1
106
+ end
107
+
108
+ if not_installed.any?
109
+ Bundler.ui.error "The following gems are missing"
110
+ not_installed.each { |s| Bundler.ui.error " * #{s.name} (#{s.version})" }
111
+ Bundler.ui.warn "Install missing gems with `bundle install`"
112
+ exit 1
113
+ else
114
+ Bundler.load.lock
115
+ Bundler.ui.info "The Gemfile's dependencies are satisfied"
116
+ end
117
+ end
118
+
119
+ desc "install", "Install the current environment to the system"
120
+ long_desc <<-D
121
+ Install will install all of the gems in the current bundle, making them available
122
+ for use. In a freshly checked out repository, this command will give you the same
123
+ gem versions as the last person who updated the Gemfile and ran `bundle update`.
124
+
125
+ Passing [DIR] to install (e.g. vendor) will cause the unpacked gems to be installed
126
+ into the [DIR] directory rather than into system gems.
127
+
128
+ If the bundle has already been installed, bundler will tell you so and then exit.
129
+ D
130
+ method_option "without", :type => :array, :banner =>
131
+ "Exclude gems that are part of the specified named group."
132
+ method_option "disable-shared-gems", :type => :boolean, :banner =>
133
+ "This option is deprecated. Please do not use it."
134
+ method_option "gemfile", :type => :string, :banner =>
135
+ "Use the specified gemfile instead of Gemfile"
136
+ method_option "no-prune", :type => :boolean, :banner =>
137
+ "Don't remove stale gems from the cache."
138
+ method_option "no-cache", :type => :boolean, :banner =>
139
+ "Don't update the existing gem cache."
140
+ method_option "quiet", :type => :boolean, :banner =>
141
+ "Only output warnings and errors."
142
+ method_option "local", :type => :boolean, :banner =>
143
+ "Do not attempt to fetch gems remotely and use the gem cache instead"
144
+ method_option "binstubs", :type => :string, :lazy_default => "bin", :banner =>
145
+ "Generate bin stubs for bundled gems to ./bin"
146
+ method_option "path", :type => :string, :banner =>
147
+ "Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME). Bundler will remember this value for future installs on this machine"
148
+ method_option "system", :type => :boolean, :banner =>
149
+ "Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application"
150
+ method_option "frozen", :type => :boolean, :banner =>
151
+ "Do not allow the Gemfile.lock to be updated after this install"
152
+ method_option "deployment", :type => :boolean, :banner =>
153
+ "Install using defaults tuned for deployment environments"
154
+ method_option "production", :type => :boolean, :banner =>
155
+ "Deprecated, please use --deployment instead"
156
+ def install(path = nil)
157
+ opts = options.dup
158
+ opts[:without] ||= []
159
+ if opts[:without].size == 1
160
+ opts[:without].map!{|g| g.split(" ") }
161
+ opts[:without].flatten!
162
+ end
163
+ opts[:without].map!{|g| g.to_sym }
164
+
165
+
166
+ ENV['BUNDLE_GEMFILE'] = File.expand_path(opts[:gemfile]) if opts[:gemfile]
167
+
168
+ if opts[:production]
169
+ opts[:deployment] = true
170
+ Bundler.ui.warn "The --production option is deprecated, and will be removed in " \
171
+ "the final release of Bundler 1.0. Please use --deployment instead."
172
+ end
173
+
174
+ if (path || opts[:path] || opts[:deployment]) && opts[:system]
175
+ Bundler.ui.error "You have specified both a path to install your gems to, \n" \
176
+ "as well as --system. Please choose."
177
+ exit 1
178
+ end
179
+
180
+ if path && opts[:path]
181
+ Bundler.ui.error "You have specified a path via `bundle install #{path}` as well as\n" \
182
+ "by `bundle install --path #{options[:path]}`. These options are\n" \
183
+ "equivalent, so please use one or the other."
184
+ exit 1
185
+ end
186
+
187
+ if opts["disable-shared-gems"]
188
+ Bundler.ui.error "The disable-shared-gem option is no longer available.\n\n" \
189
+ "Instead, use `bundle install` to install to your system,\n" \
190
+ "or `bundle install --path path/to/gems` to install to an isolated\n" \
191
+ "location. Bundler will resolve relative paths relative to\n" \
192
+ "your `Gemfile`."
193
+ exit 1
194
+ end
195
+
196
+ if opts[:deployment] || opts[:frozen]
197
+ unless Bundler.default_lockfile.exist?
198
+ flag = opts[:deployment] ? '--deployment' : '--frozen'
199
+ raise ProductionError, "The #{flag} flag requires a Gemfile.lock. Please make " \
200
+ "sure you have checked your Gemfile.lock into version control " \
201
+ "before deploying."
202
+ end
203
+
204
+ if Bundler.root.join("vendor/cache").exist?
205
+ opts[:local] = true
206
+ end
207
+
208
+ Bundler.settings[:frozen] = '1'
209
+ end
210
+
211
+ # Can't use Bundler.settings for this because settings needs gemfile.dirname
212
+ Bundler.settings[:path] = nil if opts[:system]
213
+ Bundler.settings[:path] = "vendor/bundle" if opts[:deployment]
214
+ Bundler.settings[:path] = path if path
215
+ Bundler.settings[:path] = opts[:path] if opts[:path]
216
+ Bundler.settings[:bin] = opts["binstubs"] if opts[:binstubs]
217
+ Bundler.settings[:disable_shared_gems] = '1' if Bundler.settings[:path]
218
+ Bundler.settings.without = opts[:without] unless opts[:without].empty?
219
+ Bundler.ui.be_quiet! if opts[:quiet]
220
+
221
+ Installer.install(Bundler.root, Bundler.definition, opts)
222
+ Bundler.load.cache if Bundler.root.join("vendor/cache").exist?
223
+
224
+ if Bundler.settings[:path]
225
+ relative_path = Bundler.settings[:path]
226
+ relative_path = "./" + relative_path unless relative_path[0] == ?/
227
+ Bundler.ui.confirm "Your bundle is complete! " +
228
+ "It was installed into #{relative_path}"
229
+ else
230
+ Bundler.ui.confirm "Your bundle is complete! " +
231
+ "Use `bundle show [gemname]` to see where a bundled gem is installed."
232
+ end
233
+
234
+ if path
235
+ Bundler.ui.warn "The path argument to `bundle install` is deprecated. " +
236
+ "It will be removed in version 1.1. " +
237
+ "Please use `bundle install --path #{path}` instead."
238
+ end
239
+ rescue GemNotFound => e
240
+ if opts[:local]
241
+ Bundler.ui.warn "Some gems seem to be missing from your vendor/cache directory."
242
+ end
243
+
244
+ if Bundler.definition.no_sources?
245
+ Bundler.ui.warn "Your Gemfile doesn't have any sources. You can add one with a line like 'source :rubygems'"
246
+ end
247
+ raise e
248
+ end
249
+
250
+ desc "update", "update the current environment"
251
+ long_desc <<-D
252
+ Update will install the newest versions of the gems listed in the Gemfile. Use
253
+ update when you have changed the Gemfile, or if you want to get the newest
254
+ possible versions of the gems in the bundle.
255
+ D
256
+ method_option "source", :type => :array, :banner => "Update a specific source (and all gems associated with it)"
257
+ def update(*gems)
258
+ sources = Array(options[:source])
259
+
260
+ if gems.empty? && sources.empty?
261
+ # We're doing a full update
262
+ Bundler.definition(true)
263
+ else
264
+ Bundler.definition(:gems => gems, :sources => sources)
265
+ end
266
+
267
+ Installer.install Bundler.root, Bundler.definition, "update" => true
268
+ Bundler.load.cache if Bundler.root.join("vendor/cache").exist?
269
+ Bundler.ui.confirm "Your bundle is updated! " +
270
+ "Use `bundle show [gemname]` to see where a bundled gem is installed."
271
+ end
272
+
273
+ desc "lock", "Locks the bundle to the current set of dependencies, including all child dependencies."
274
+ def lock
275
+ Bundler.ui.warn "Lock is deprecated. Your bundle is now locked whenever you run `bundle install`."
276
+ end
277
+
278
+ desc "unlock", "Unlock the bundle. This allows gem versions to be changed."
279
+ def unlock
280
+ Bundler.ui.warn "Unlock is deprecated. To update to newer gem versions, use `bundle update`."
281
+ end
282
+
283
+ desc "show [GEM]", "Shows all gems that are part of the bundle, or the path to a given gem"
284
+ long_desc <<-D
285
+ Show lists the names and versions of all gems that are required by your Gemfile.
286
+ Calling show with [GEM] will list the exact location of that gem on your machine.
287
+ D
288
+ def show(gem_name = nil)
289
+ Bundler.load.lock
290
+
291
+ if gem_name
292
+ Bundler.ui.info locate_gem(gem_name)
293
+ else
294
+ Bundler.ui.info "Gems included by the bundle:"
295
+ Bundler.load.specs.sort_by { |s| s.name }.each do |s|
296
+ Bundler.ui.info " * #{s.name} (#{s.version}#{s.git_version})"
297
+ end
298
+ end
299
+ end
300
+ map %w(list) => "show"
301
+
302
+ desc "cache", "Cache all the gems to vendor/cache", :hide => true
303
+ method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
304
+ def cache
305
+ Bundler.definition.resolve_with_cache!
306
+ Bundler.load.cache
307
+ Bundler.settings[:no_prune] = true if options[:no_prune]
308
+ Bundler.load.lock
309
+ rescue GemNotFound => e
310
+ Bundler.ui.error(e.message)
311
+ Bundler.ui.warn "Run `bundle install` to install missing gems."
312
+ exit 128
313
+ end
314
+
315
+ desc "package", "Locks and then caches all of the gems into vendor/cache"
316
+ method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
317
+ long_desc <<-D
318
+ The package command will copy the .gem files for every gem in the bundle into the
319
+ directory ./vendor/cache. If you then check that directory into your source
320
+ control repository, others who check out your source will be able to install the
321
+ bundle without having to download any additional gems.
322
+ D
323
+ def package
324
+ install
325
+ # TODO: move cache contents here now that all bundles are locked
326
+ Bundler.load.cache
327
+ end
328
+ map %w(pack) => :package
329
+
330
+ desc "exec", "Run the command in context of the bundle"
331
+ long_desc <<-D
332
+ Exec runs a command, providing it access to the gems in the bundle. While using
333
+ bundle exec you can require and call the bundled gems as if they were installed
334
+ into the systemwide Rubygems repository.
335
+ D
336
+ def exec(*)
337
+ ARGV.delete("exec")
338
+
339
+ Bundler.setup
340
+
341
+ begin
342
+ # Run
343
+ Kernel.exec(*ARGV)
344
+ rescue Errno::EACCES
345
+ Bundler.ui.error "bundler: not executable: #{ARGV.first}"
346
+ exit 126
347
+ rescue Errno::ENOENT
348
+ Bundler.ui.error "bundler: command not found: #{ARGV.first}"
349
+ Bundler.ui.warn "Install missing gem binaries with `bundle install`"
350
+ exit 127
351
+ end
352
+ end
353
+
354
+ desc "config NAME [VALUE]", "retrieve or set a configuration value"
355
+ long_desc <<-D
356
+ Retrieves or sets a configuration value. If only parameter is provided, retrieve the value. If two parameters are provided, replace the
357
+ existing value with the newly provided one.
358
+
359
+ By default, setting a configuration value sets it for all projects
360
+ on the machine.
361
+
362
+ If a global setting is superceded by local configuration, this command
363
+ will show the current value, as well as any superceded values and
364
+ where they were specified.
365
+ D
366
+ def config(name = nil, *args)
367
+ values = ARGV.dup
368
+ values.shift # remove config
369
+ values.shift # remove the name
370
+
371
+ unless name
372
+ Bundler.ui.confirm "Settings are listed in order of priority. The top value will be used.\n"
373
+
374
+ Bundler.settings.all.each do |setting|
375
+ Bundler.ui.confirm "#{setting}"
376
+ with_padding do
377
+ Bundler.settings.pretty_values_for(setting).each do |line|
378
+ Bundler.ui.info line
379
+ end
380
+ end
381
+ Bundler.ui.confirm ""
382
+ end
383
+ return
384
+ end
385
+
386
+ if values.empty?
387
+ Bundler.ui.confirm "Settings for `#{name}` in order of priority. The top value will be used"
388
+ with_padding do
389
+ Bundler.settings.pretty_values_for(name).each { |line| Bundler.ui.info line }
390
+ end
391
+ else
392
+ locations = Bundler.settings.locations(name)
393
+
394
+ if local = locations[:local]
395
+ Bundler.ui.info "Your application has set #{name} to #{local.inspect}. This will override the " \
396
+ "system value you are currently setting"
397
+ end
398
+
399
+ if global = locations[:global]
400
+ Bundler.ui.info "You are replacing the current system value of #{name}, which is currently #{global}"
401
+ end
402
+
403
+ if env = locations[:env]
404
+ Bundler.ui.info "You have set a bundler environment variable for #{env}. This will take precedence " \
405
+ "over the system value you are setting"
406
+ end
407
+
408
+ Bundler.settings.set_global(name, values.join(" "))
409
+ end
410
+ end
411
+
412
+ desc "open GEM", "Opens the source directory of the given bundled gem"
413
+ def open(name)
414
+ editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
415
+ if editor
416
+ gem_path = locate_gem(name)
417
+ Dir.chdir(gem_path) do
418
+ command = "#{editor} #{gem_path}"
419
+ success = system(command)
420
+ Bundler.ui.info "Could not run '#{command}'" unless success
421
+ end
422
+ else
423
+ Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR")
424
+ end
425
+ end
426
+
427
+ desc "console [GROUP]", "Opens an IRB session with the bundle pre-loaded"
428
+ def console(group = nil)
429
+ require 'bundler/setup'
430
+ group ? Bundler.require(:default, group) : Bundler.require
431
+ ARGV.clear
432
+
433
+ require 'irb'
434
+ IRB.start
435
+ end
436
+
437
+ desc "version", "Prints the bundler's version information"
438
+ def version
439
+ Bundler.ui.info "Bundler version #{Bundler::VERSION}"
440
+ end
441
+ map %w(-v --version) => :version
442
+
443
+ desc 'viz', "Generates a visual dependency graph"
444
+ long_desc <<-D
445
+ Viz generates a PNG file of the current Gemfile as a dependency graph.
446
+ Viz requires the ruby-graphviz gem (and its dependencies).
447
+ The associated gems must also be installed via 'bundle install'.
448
+ D
449
+ method_option :file, :type => :string, :default => 'gem_graph.png', :aliases => '-f', :banner => "The name to use for the generated png file."
450
+ method_option :version, :type => :boolean, :default => false, :aliases => '-v', :banner => "Set to show each gem version."
451
+ method_option :requirements, :type => :boolean, :default => false, :aliases => '-r', :banner => "Set to show the version of each required dependency."
452
+ def viz
453
+ output_file = File.expand_path(options[:file])
454
+ graph = Graph.new( Bundler.load )
455
+
456
+ begin
457
+ graph.viz(output_file, options[:version], options[:requirements])
458
+ Bundler.ui.info output_file
459
+ rescue LoadError => e
460
+ Bundler.ui.error e.inspect
461
+ Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
462
+ Bundler.ui.warn "`gem install ruby-graphviz`"
463
+ rescue StandardError => e
464
+ if e.message =~ /GraphViz not installed or dot not in PATH/
465
+ Bundler.ui.error e.message
466
+ Bundler.ui.warn "The ruby graphviz gem requires GraphViz to be installed"
467
+ else
468
+ raise
469
+ end
470
+ end
471
+ end
472
+
473
+ desc "gem GEM", "Creates a skeleton for creating a rubygem"
474
+ method_option :bin, :type => :boolean, :default => false, :aliases => '-b', :banner => "Generate a binary for your library."
475
+ def gem(name)
476
+ target = File.join(Dir.pwd, name)
477
+ constant_name = name.split('_').map{|p| p.capitalize}.join
478
+ constant_name = constant_name.split('-').map{|q| q.capitalize}.join('::') if constant_name =~ /-/
479
+ constant_array = constant_name.split('::')
480
+ FileUtils.mkdir_p(File.join(target, 'lib', name))
481
+ opts = {:name => name, :constant_name => constant_name, :constant_array => constant_array}
482
+ template(File.join("newgem/Gemfile.tt"), File.join(target, "Gemfile"), opts)
483
+ template(File.join("newgem/Rakefile.tt"), File.join(target, "Rakefile"), opts)
484
+ template(File.join("newgem/gitignore.tt"), File.join(target, ".gitignore"), opts)
485
+ template(File.join("newgem/newgem.gemspec.tt"), File.join(target, "#{name}.gemspec"), opts)
486
+ template(File.join("newgem/lib/newgem.rb.tt"), File.join(target, "lib/#{name}.rb"), opts)
487
+ template(File.join("newgem/lib/newgem/version.rb.tt"), File.join(target, "lib/#{name}/version.rb"), opts)
488
+ if options[:bin]
489
+ template(File.join("newgem/bin/newgem.tt"), File.join(target, 'bin', name), opts)
490
+ end
491
+ Bundler.ui.info "Initializating git repo in #{target}"
492
+ Dir.chdir(target) { `git init`; `git add .` }
493
+ end
494
+
495
+ def self.source_root
496
+ File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
497
+ end
498
+
499
+ private
500
+
501
+ def have_groff?
502
+ `which groff 2>#{NULL}`
503
+ $? == 0
504
+ end
505
+
506
+ def locate_gem(name)
507
+ spec = Bundler.load.specs.find{|s| s.name == name }
508
+ raise GemNotFound, "Could not find gem '#{name}' in the current bundle." unless spec
509
+ if spec.name == 'bundler'
510
+ return File.expand_path('../../../', __FILE__)
511
+ end
512
+ spec.full_gem_path
513
+ end
514
+ end
515
+ end