Class: Coherent::Commands::List

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

Instance Method Summary collapse

Constructor Details

#initialize(base_command) ⇒ List

Returns a new instance of List.



5
6
7
8
9
10
# File 'lib/plugin/commands/list.rb', line 5

def initialize(base_command)
  @base_command = base_command
  @sources = []
  @local = false
  @remote = true
end

Instance Method Details

#optionsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/plugin/commands/list.rb', line 12

def options
  OptionParser.new do |o|
    o.set_summary_indent('  ')
    o.banner =    "Usage: #{@base_command.script_name} list [OPTIONS] [PATTERN]"
    o.define_head "List available plugins."
    o.separator   ""        
    o.separator   "Options:"
    o.separator   ""
    o.on(         "-s", "--source=URL1,URL2", Array,
                  "Use the specified plugin repositories.") {|sources| @sources = sources}
    o.on(         "--local", 
                  "List locally installed plugins.") {|local| @local, @remote = local, false}
    o.on(         "--remote",
                  "List remotely available plugins. This is the default behavior",
                  "unless --local is provided.") {|remote| @remote = remote}
  end
end

#parse!(args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/plugin/commands/list.rb', line 30

def parse!(args)
  options.order!(args)
  unless @sources.empty?
    @sources.map!{ |uri| Repository.new(uri) }
  else
    @sources = Repositories.instance.all
  end
  if @remote
    @sources.map{|r| r.plugins}.flatten.each do |plugin| 
      if @local or !plugin.installed?
        puts plugin.to_s
      end
    end
  else
    cd "#{@base_command.environment.root}/vendor/plugins"
    Dir["*"].select{|p| File.directory?(p)}.each do |name| 
      puts name
    end
  end
end