Class: Commands::List
- Inherits:
-
Object
- Object
- Commands::List
- Defined in:
- lib/commands/plugin/commands.rb
Instance Method Summary collapse
-
#initialize(base_command) ⇒ List
constructor
A new instance of List.
- #options ⇒ Object
- #parse!(args) ⇒ Object
Constructor Details
#initialize(base_command) ⇒ List
Returns a new instance of List.
125 126 127 128 129 130 131 |
# File 'lib/commands/plugin/commands.rb', line 125 def initialize(base_command) @base_command = base_command @sources = [] @local = false @remote = false @cached = true end |
Instance Method Details
#options ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/commands/plugin/commands.rb', line 133 def OptionParser.new do |o| o.set_summary_indent(' ') o. = "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| @remote = true; @cached = false } o.on( "--local", "List locally installed plugins.") {|@local| @cached = false } o.on( "--cached", "List the known plugins in the local sources cache. This is the default behavior.") {|@cached|} o.on( "--remote", "List remotely available plugins.", "unless --local is provided.") {|@remote| @cached = false } end end |
#parse!(args) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/commands/plugin/commands.rb', line 153 def parse!(args) .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 elsif @cached Repositories.instance.cached_plugins.each { |plugin| puts plugin.to_s } puts "\nThere are #{Repositories.instance.plugin_count} plugins in the source cache.\n\n" else cd "#{@base_command.environment.root}/vendor/plugins" Dir["*"].select{|p| File.directory?(p)}.each do |name| puts name end end end |