Class: Commands::Plugin

Inherits:
Object show all
Defined in:
lib/commands/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



402
403
404
405
406
407
# File 'lib/commands/plugin.rb', line 402

def initialize
  @environment = RailsEnvironment.default
  @rails_root = RailsEnvironment.default.root
  @script_name = File.basename($0) 
  @sources = []
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



401
402
403
# File 'lib/commands/plugin.rb', line 401

def environment
  @environment
end

#script_nameObject (readonly)

Returns the value of attribute script_name.



401
402
403
# File 'lib/commands/plugin.rb', line 401

def script_name
  @script_name
end

#sourcesObject (readonly)

Returns the value of attribute sources.



401
402
403
# File 'lib/commands/plugin.rb', line 401

def sources
  @sources
end

Class Method Details

.parse!(args = ARGV) ⇒ Object



491
492
493
# File 'lib/commands/plugin.rb', line 491

def self.parse!(args=ARGV)
  Plugin.new.parse!(args)
end

Instance Method Details

#optionsObject



414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/commands/plugin.rb', line 414

def options
  OptionParser.new do |o|
    o.set_summary_indent('  ')
    o.banner =    "Usage: #{@script_name} [OPTIONS] command"
    o.define_head "Rails plugin manager."
    
    o.separator ""        
    o.separator "GENERAL OPTIONS"
    
    o.on("-r", "--root=DIR", String,
         "Set an explicit rails app directory.",
         "Default: #{@rails_root}") { |@rails_root| self.environment = RailsEnvironment.new(@rails_root) }
    o.on("-s", "--source=URL1,URL2", Array,
         "Use the specified plugin repositories instead of the defaults.") { |@sources|}
    
    o.on("-v", "--verbose", "Turn on verbose output.") { |$verbose| }
    o.on("-h", "--help", "Show this help message.") { puts o; exit }
    
    o.separator ""
    o.separator "COMMANDS"
    
    o.separator "  discover   Discover plugin repositories."
    o.separator "  list       List available plugins."
    o.separator "  install    Install plugin(s) from known repositories or URLs."
    o.separator "  update     Update installed plugins."
    o.separator "  remove     Uninstall plugins."
    o.separator "  source     Add a plugin source repository."
    o.separator "  unsource   Remove a plugin repository."
    o.separator "  sources    List currently configured plugin repositories."
    
    o.separator ""
    o.separator "EXAMPLES"
    o.separator "  Install a plugin:"
    o.separator "    #{@script_name} install continuous_builder\n"
    o.separator "  Install a plugin from a subversion URL:"
    o.separator "    #{@script_name} install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder\n"
    o.separator "  Install a plugin and add a svn:externals entry to vendor/plugins"
    o.separator "    #{@script_name} install -x continuous_builder\n"
    o.separator "  List all available plugins:"
    o.separator "    #{@script_name} list\n"
    o.separator "  List plugins in the specified repository:"
    o.separator "    #{@script_name} list --source=http://dev.rubyonrails.com/svn/rails/plugins/\n"
    o.separator "  Discover and prompt to add new repositories:"
    o.separator "    #{@script_name} discover\n"
    o.separator "  Discover new repositories but just list them, don't add anything:"
    o.separator "    #{@script_name} discover -l\n"
    o.separator "  Add a new repository to the source list:"
    o.separator "    #{@script_name} source http://dev.rubyonrails.com/svn/rails/plugins/\n"
    o.separator "  Remove a repository from the source list:"
    o.separator "    #{@script_name} unsource http://dev.rubyonrails.com/svn/rails/plugins/\n"
    o.separator "  Show currently configured repositories:"
    o.separator "    #{@script_name} sources\n"        
  end
end

#parse!(args = ARGV) ⇒ Object



469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/commands/plugin.rb', line 469

def parse!(args=ARGV)
  general, sub = split_args(args)
  options.parse!(general)
  
  command = general.shift
  if command =~ /^(list|discover|install|source|unsource|sources|remove|update|info)$/
    command = Commands.const_get(command.capitalize).new(self)
    command.parse!(sub)
  else
    puts "Unknown command: #{command}"
    puts options
    exit 1
  end
end

#split_args(args) ⇒ Object



484
485
486
487
488
489
# File 'lib/commands/plugin.rb', line 484

def split_args(args)
  left = []
  left << args.shift while args[0] and args[0] =~ /^-/
  left << args.shift if args[0]
  return [left, args]
end