Class: VimGet::Commands::ListCommand

Inherits:
BaseCommand show all
Defined in:
lib/vimget/commands/list_command.rb

Direct Known Subclasses

InstalledCommand, OutdatedCommand

Constant Summary

Constants inherited from BaseCommand

BaseCommand::PROGRAM

Instance Attribute Summary

Attributes inherited from BaseCommand

#command, #defaults, #options, #options_group, #program_name, #summary

Instance Method Summary collapse

Methods inherited from BaseCommand

#arguments, #invoke, #show_help

Constructor Details

#initialize(name = 'list', summary = 'Display all script in local') ⇒ ListCommand

Returns a new instance of ListCommand.



14
15
16
17
18
19
20
# File 'lib/vimget/commands/list_command.rb', line 14

def initialize(name = 'list', summary = 'Display all script in local')
  super(name,
    summary,
    :format => "plain")
  
  add_customer_options
end

Instance Method Details

#executeObject

Raises:



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
# File 'lib/vimget/commands/list_command.rb', line 26

def execute
  raise CommandLineError, "Ambiguous command!" if @options[:outdated] && @options[:installed]
    
  if @options[:outdated]
    puts "List outdated scripts"
    scripts = VimGet.db.outdated_scripts
  elsif @options[:installed]
    puts "List installed scripts"
    scripts = VimGet.db.installed_scripts
  else
    puts "List scripts"
    scripts = VimGet.db.search
  end
 
  scripts.each do |s|
    if @options[:format] == "plain"
      puts "[#{s.name}]"
      puts "id: #{s.sid}"
      puts "author: #{s.author}"
      puts "installed: #{s.installed}"
      puts "version: #{s.version}"
      puts
    #elsif @options[:format] == "xml"
    #  puts "<script name=\"#{s.name}\" id=\"#{s.sid}\">"
    #  puts "</script>"
    end
  end
end

#usageObject



22
23
24
# File 'lib/vimget/commands/list_command.rb', line 22

def usage
  "#{program_name} [STRING]"
end