Class: VimGet::Commands::UninstallCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/vimget/commands/uninstall_command.rb

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, #usage

Constructor Details

#initializeUninstallCommand

Returns a new instance of UninstallCommand.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vimget/commands/uninstall_command.rb', line 23

def initialize
  super("uninstall", "Uninstall a script")
  
  add_option("-i", 
        "--id ID", 
        Integer, 
        "Indicated the id of script to uninstall")  { |v,opts| opts[:uninstall_id] = v }
  
  add_option('--purge', 
      'Remove all associated files, including vim-get manifest') { |v,opts| opts[:purge] = v }
      
  add_option('--dry-run', 
      'Do not motify any files') { |v,opts| opts[:dry_run] = v }
end

Instance Method Details

#executeObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vimget/commands/uninstall_command.rb', line 38

def execute
  if @options[:uninstall_id]
    script = VimGet.db.find_with_id(@options[:uninstall_id])
  else
    @rest.shift if @rest.first == "uninstall"
    raise CommandLineError, "Missing arguments" if @rest.empty?
    
    name = @rest.first
    script = VimGet.db.find(name)
  end
  
  if script.nil?
    raise UnknownScriptError, "This script is not installed yet." 
  end
  
  installer = Installer.new(@options)
  installer.uninstall(script)
end