Skip to content
This repository
Browse code

Substituted RailsCommands for Rails::Commands

  • Loading branch information...
commit 325abe9fbad58b6a0e119a678039b195247a57bc 1 parent 21c5a0a
Daniel Dyba dyba authored tenderlove committed

Showing 1 changed file with 161 additions and 159 deletions. Show diff stats Hide diff stats

  1. +161 159 railties/lib/rails/commands/plugin.rb
320 railties/lib/rails/commands/plugin.rb
@@ -274,198 +274,200 @@ def rails_env
274 274
275 275 # load default environment and parse arguments
276 276 require 'optparse'
277   -module RailsCommands
278   - class Plugin
279   - attr_reader :environment, :script_name
280   - def initialize
281   - @environment = RailsEnvironment.default
282   - @rails_root = RailsEnvironment.default.root
283   - @script_name = File.basename($0)
284   - end
  277 +module Rails
  278 + module Commands
  279 + class Plugin
  280 + attr_reader :environment, :script_name
  281 + def initialize
  282 + @environment = RailsEnvironment.default
  283 + @rails_root = RailsEnvironment.default.root
  284 + @script_name = File.basename($0)
  285 + end
285 286
286   - def environment=(value)
287   - @environment = value
288   - RailsEnvironment.default = value
289   - end
  287 + def environment=(value)
  288 + @environment = value
  289 + RailsEnvironment.default = value
  290 + end
290 291
291   - def options
292   - OptionParser.new do |o|
293   - o.set_summary_indent(' ')
294   - o.banner = "Usage: plugin [OPTIONS] command"
295   - o.define_head "Rails plugin manager."
  292 + def options
  293 + OptionParser.new do |o|
  294 + o.set_summary_indent(' ')
  295 + o.banner = "Usage: plugin [OPTIONS] command"
  296 + o.define_head "Rails plugin manager."
296 297
297   - o.separator ""
298   - o.separator "GENERAL OPTIONS"
  298 + o.separator ""
  299 + o.separator "GENERAL OPTIONS"
299 300
300   - o.on("-r", "--root=DIR", String,
301   - "Set an explicit rails app directory.",
302   - "Default: #{@rails_root}") { |rails_root| @rails_root = rails_root; self.environment = RailsEnvironment.new(@rails_root) }
  301 + o.on("-r", "--root=DIR", String,
  302 + "Set an explicit rails app directory.",
  303 + "Default: #{@rails_root}") { |rails_root| @rails_root = rails_root; self.environment = RailsEnvironment.new(@rails_root) }
303 304
304   - o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose }
305   - o.on("-h", "--help", "Show this help message.") { puts o; exit }
  305 + o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose }
  306 + o.on("-h", "--help", "Show this help message.") { puts o; exit }
306 307
307   - o.separator ""
308   - o.separator "COMMANDS"
  308 + o.separator ""
  309 + o.separator "COMMANDS"
309 310
310   - o.separator " install Install plugin(s) from known repositories or URLs."
311   - o.separator " remove Uninstall plugins."
  311 + o.separator " install Install plugin(s) from known repositories or URLs."
  312 + o.separator " remove Uninstall plugins."
312 313
313   - o.separator ""
314   - o.separator "EXAMPLES"
315   - o.separator " Install a plugin from a subversion URL:"
316   - o.separator " #{@script_name} plugin install http://example.com/my_svn_plugin\n"
317   - o.separator " Install a plugin from a git URL:"
318   - o.separator " #{@script_name} plugin install git://github.com/SomeGuy/my_awesome_plugin.git\n"
319   - o.separator " Install a plugin and add a svn:externals entry to vendor/plugins"
320   - o.separator " #{@script_name} plugin install -x my_svn_plugin\n"
  314 + o.separator ""
  315 + o.separator "EXAMPLES"
  316 + o.separator " Install a plugin from a subversion URL:"
  317 + o.separator " #{@script_name} plugin install http://example.com/my_svn_plugin\n"
  318 + o.separator " Install a plugin from a git URL:"
  319 + o.separator " #{@script_name} plugin install git://github.com/SomeGuy/my_awesome_plugin.git\n"
  320 + o.separator " Install a plugin and add a svn:externals entry to vendor/plugins"
  321 + o.separator " #{@script_name} plugin install -x my_svn_plugin\n"
  322 + end
321 323 end
322   - end
323 324
324   - def parse!(args=ARGV)
325   - general, sub = split_args(args)
326   - options.parse!(general)
  325 + def parse!(args=ARGV)
  326 + general, sub = split_args(args)
  327 + options.parse!(general)
327 328
328   - command = general.shift
329   - if command =~ /^(install|remove)$/
330   - command = RailsCommands.const_get(command.capitalize).new(self)
331   - command.parse!(sub)
332   - else
333   - puts "Unknown command: #{command}" unless command.blank?
334   - puts options
335   - exit 1
  329 + command = general.shift
  330 + if command =~ /^(install|remove)$/
  331 + command = Commands.const_get(command.capitalize).new(self)
  332 + command.parse!(sub)
  333 + else
  334 + puts "Unknown command: #{command}" unless command.blank?
  335 + puts options
  336 + exit 1
  337 + end
336 338 end
337   - end
338 339
339   - def split_args(args)
340   - left = []
341   - left << args.shift while args[0] and args[0] =~ /^-/
342   - left << args.shift if args[0]
343   - [left, args]
344   - end
345   -
346   - def self.parse!(args=ARGV)
347   - Plugin.new.parse!(args)
348   - end
349   - end
  340 + def split_args(args)
  341 + left = []
  342 + left << args.shift while args[0] and args[0] =~ /^-/
  343 + left << args.shift if args[0]
  344 + [left, args]
  345 + end
350 346
351   - class Install
352   - def initialize(base_command)
353   - @base_command = base_command
354   - @method = :http
355   - @options = { :quiet => false, :revision => nil, :force => false }
  347 + def self.parse!(args=ARGV)
  348 + Plugin.new.parse!(args)
  349 + end
356 350 end
357 351
358   - def options
359   - OptionParser.new do |o|
360   - o.set_summary_indent(' ')
361   - o.banner = "Usage: #{@base_command.script_name} install PLUGIN [PLUGIN [PLUGIN] ...]"
362   - o.define_head "Install one or more plugins."
363   - o.separator ""
364   - o.separator "Options:"
365   - o.on( "-x", "--externals",
366   - "Use svn:externals to grab the plugin.",
367   - "Enables plugin updates and plugin versioning.") { |v| @method = :externals }
368   - o.on( "-o", "--checkout",
369   - "Use svn checkout to grab the plugin.",
370   - "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout }
371   - o.on( "-e", "--export",
372   - "Use svn export to grab the plugin.",
373   - "Exports the plugin, allowing you to check it into your local repository. Does not enable updates or add an svn:externals entry.") { |v| @method = :export }
374   - o.on( "-q", "--quiet",
375   - "Suppresses the output from installation.",
376   - "Ignored if -v is passed (rails plugin -v install ...)") { |v| @options[:quiet] = true }
377   - o.on( "-r REVISION", "--revision REVISION",
378   - "Checks out the given revision from subversion or git.",
379   - "Ignored if subversion/git is not used.") { |v| @options[:revision] = v }
380   - o.on( "-f", "--force",
381   - "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true }
382   - o.separator ""
383   - o.separator "You can specify plugin names as given in 'plugin list' output or absolute URLs to "
384   - o.separator "a plugin repository."
  352 + class Install
  353 + def initialize(base_command)
  354 + @base_command = base_command
  355 + @method = :http
  356 + @options = { :quiet => false, :revision => nil, :force => false }
385 357 end
386   - end
387 358
388   - def determine_install_method
389   - best = @base_command.environment.best_install_method
390   - @method = :http if best == :http and @method == :export
391   - case
392   - when (best == :http and @method != :http)
393   - msg = "Cannot install using subversion because `svn' cannot be found in your PATH"
394   - when (best == :export and (@method != :export and @method != :http))
395   - msg = "Cannot install using #{@method} because this project is not under subversion."
396   - when (best != :externals and @method == :externals)
397   - msg = "Cannot install using externals because vendor/plugins is not under subversion."
  359 + def options
  360 + OptionParser.new do |o|
  361 + o.set_summary_indent(' ')
  362 + o.banner = "Usage: #{@base_command.script_name} install PLUGIN [PLUGIN [PLUGIN] ...]"
  363 + o.define_head "Install one or more plugins."
  364 + o.separator ""
  365 + o.separator "Options:"
  366 + o.on( "-x", "--externals",
  367 + "Use svn:externals to grab the plugin.",
  368 + "Enables plugin updates and plugin versioning.") { |v| @method = :externals }
  369 + o.on( "-o", "--checkout",
  370 + "Use svn checkout to grab the plugin.",
  371 + "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout }
  372 + o.on( "-e", "--export",
  373 + "Use svn export to grab the plugin.",
  374 + "Exports the plugin, allowing you to check it into your local repository. Does not enable updates or add an svn:externals entry.") { |v| @method = :export }
  375 + o.on( "-q", "--quiet",
  376 + "Suppresses the output from installation.",
  377 + "Ignored if -v is passed (rails plugin -v install ...)") { |v| @options[:quiet] = true }
  378 + o.on( "-r REVISION", "--revision REVISION",
  379 + "Checks out the given revision from subversion or git.",
  380 + "Ignored if subversion/git is not used.") { |v| @options[:revision] = v }
  381 + o.on( "-f", "--force",
  382 + "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true }
  383 + o.separator ""
  384 + o.separator "You can specify plugin names as given in 'plugin list' output or absolute URLs to "
  385 + o.separator "a plugin repository."
  386 + end
398 387 end
399   - if msg
400   - puts msg
401   - exit 1
  388 +
  389 + def determine_install_method
  390 + best = @base_command.environment.best_install_method
  391 + @method = :http if best == :http and @method == :export
  392 + case
  393 + when (best == :http and @method != :http)
  394 + msg = "Cannot install using subversion because `svn' cannot be found in your PATH"
  395 + when (best == :export and (@method != :export and @method != :http))
  396 + msg = "Cannot install using #{@method} because this project is not under subversion."
  397 + when (best != :externals and @method == :externals)
  398 + msg = "Cannot install using externals because vendor/plugins is not under subversion."
  399 + end
  400 + if msg
  401 + puts msg
  402 + exit 1
  403 + end
  404 + @method
402 405 end
403   - @method
404   - end
405 406
406   - def parse!(args)
407   - options.parse!(args)
408   - if args.blank?
409   - puts options
  407 + def parse!(args)
  408 + options.parse!(args)
  409 + if args.blank?
  410 + puts options
  411 + exit 1
  412 + end
  413 + environment = @base_command.environment
  414 + install_method = determine_install_method
  415 + puts "Plugins will be installed using #{install_method}" if $verbose
  416 + args.each do |name|
  417 + ::Plugin.find(name).install(install_method, @options)
  418 + end
  419 + rescue StandardError => e
  420 + puts "Plugin not found: #{args.inspect}"
  421 + puts e.inspect if $verbose
410 422 exit 1
411 423 end
412   - environment = @base_command.environment
413   - install_method = determine_install_method
414   - puts "Plugins will be installed using #{install_method}" if $verbose
415   - args.each do |name|
416   - ::Plugin.find(name).install(install_method, @options)
417   - end
418   - rescue StandardError => e
419   - puts "Plugin not found: #{args.inspect}"
420   - puts e.inspect if $verbose
421   - exit 1
422   - end
423   - end
424   -
425   - class Remove
426   - def initialize(base_command)
427   - @base_command = base_command
428 424 end
429 425
430   - def options
431   - OptionParser.new do |o|
432   - o.set_summary_indent(' ')
433   - o.banner = "Usage: #{@base_command.script_name} remove name [name]..."
434   - o.define_head "Remove plugins."
  426 + class Remove
  427 + def initialize(base_command)
  428 + @base_command = base_command
435 429 end
436   - end
437 430
438   - def parse!(args)
439   - options.parse!(args)
440   - if args.blank?
441   - puts options
442   - exit 1
  431 + def options
  432 + OptionParser.new do |o|
  433 + o.set_summary_indent(' ')
  434 + o.banner = "Usage: #{@base_command.script_name} remove name [name]..."
  435 + o.define_head "Remove plugins."
  436 + end
443 437 end
444   - root = @base_command.environment.root
445   - args.each do |name|
446   - ::Plugin.new(name).uninstall
  438 +
  439 + def parse!(args)
  440 + options.parse!(args)
  441 + if args.blank?
  442 + puts options
  443 + exit 1
  444 + end
  445 + root = @base_command.environment.root
  446 + args.each do |name|
  447 + ::Plugin.new(name).uninstall
  448 + end
447 449 end
448 450 end
449   - end
450 451
451   - class Info
452   - def initialize(base_command)
453   - @base_command = base_command
454   - end
  452 + class Info
  453 + def initialize(base_command)
  454 + @base_command = base_command
  455 + end
455 456
456   - def options
457   - OptionParser.new do |o|
458   - o.set_summary_indent(' ')
459   - o.banner = "Usage: #{@base_command.script_name} info name [name]..."
460   - o.define_head "Shows plugin info at {url}/about.yml."
  457 + def options
  458 + OptionParser.new do |o|
  459 + o.set_summary_indent(' ')
  460 + o.banner = "Usage: #{@base_command.script_name} info name [name]..."
  461 + o.define_head "Shows plugin info at {url}/about.yml."
  462 + end
461 463 end
462   - end
463 464
464   - def parse!(args)
465   - options.parse!(args)
466   - args.each do |name|
467   - puts ::Plugin.find(name).info
468   - puts
  465 + def parse!(args)
  466 + options.parse!(args)
  467 + args.each do |name|
  468 + puts ::Plugin.find(name).info
  469 + puts
  470 + end
469 471 end
470 472 end
471 473 end
@@ -539,4 +541,4 @@ def fetch_dir(url)
539 541 end
540 542 end
541 543
542   -RailsCommands::Plugin.parse!
  544 +Rails::Commands::Plugin.parse!

0 comments on commit 325abe9

Please sign in to comment.
Something went wrong with that request. Please try again.