Class: Commands::Plugin

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



8
9
10
11
12
13
# File 'lib/commands/plugin/commands.rb', line 8

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.



7
8
9
# File 'lib/commands/plugin/commands.rb', line 7

def environment
  @environment
end

#script_nameObject (readonly)

Returns the value of attribute script_name.



7
8
9
# File 'lib/commands/plugin/commands.rb', line 7

def script_name
  @script_name
end

#sourcesObject (readonly)

Returns the value of attribute sources.



7
8
9
# File 'lib/commands/plugin/commands.rb', line 7

def sources
  @sources
end

Class Method Details

.parse!(args = ARGV) ⇒ Object



116
117
118
# File 'lib/commands/plugin/commands.rb', line 116

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

Instance Method Details

#optionsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/commands/plugin/commands.rb', line 20

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 "  search         Search for available plugins."
    o.separator "  about          Show basic info about a plugin."
    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 "  pack:install   Install plugins from plugin pack file or URL"
    o.separator "  pack:uninstall Uninstall plugins from plugin pack file or URL"
    o.separator "  pack:about     Display plugin pack information"
    
    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 "  Show information about the acts_as_chunky_bacon plugin:"
    o.separator "    #{@script_name} about acts_as_chunky_bacon\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 "  Search available plugins:"
    o.separator "    #{@script_name} search \"authentication\"\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"        
    o.separator "  Show the options for the list command:"
    o.separator "    #{@script_name} list -h\n"
    o.separator "  Install a plugin pack:"
    o.separator "    #{@script_name} pack:install http://opensource.agileevolved.com/pluginpacks/standard.pluginpack\n"
    o.separator "  View plugin pack meta data:"
    o.separator "    #{@script_name} pack:about http://opensource.agileevolved.com/pluginpacks/standard.pluginpack\n"
  end
end

#parse!(args = ARGV) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/commands/plugin/commands.rb', line 90

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|about|search)$/
    command = Commands.const_get(command.capitalize).new(self)
    command.parse!(sub)
  elsif command =~ /^(pack:install|pack:uninstall|pack:about)$/
    command_name = command.split(':')[1]
    command = Commands::Pack.const_get(command_name.capitalize).new(self)
    command.parse!(sub)
  else
    puts "Unknown command: #{command}"
    puts options
    exit 1
  end
end

#split_args(args) ⇒ Object



109
110
111
112
113
114
# File 'lib/commands/plugin/commands.rb', line 109

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