Class: VimGet::Commands::InstallCommand

Inherits:
BaseCommand show all
Defined in:
lib/vimget/commands/install_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

#invoke, #show_help

Constructor Details

#initializeInstallCommand

Returns a new instance of InstallCommand.



25
26
27
28
29
# File 'lib/vimget/commands/install_command.rb', line 25

def initialize
  super('install', "Install a script")
  
  custom_options
end

Instance Method Details

#argumentsObject



35
36
37
# File 'lib/vimget/commands/install_command.rb', line 35

def arguments
  "NAME    name of script to install"
end

#executeObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vimget/commands/install_command.rb', line 39

def execute
  if @options[:install_id]
    script = VimGet.db.find_with_id @options[:install_id]
    
    if script.nil?
      script = VimGet.parse_script_page(@options[:install_id])
      VimGet.db.add(script)
    end
  else
    @rest.shift if @rest.first == "install"
    if @rest.empty?
      raise CommandLineError, "Missing arguments"
    end
    
    name = @rest.first
    
    script = VimGet.db.find(name)
    
    raise UnknownScriptError, "Unknow script!" if script.nil?
  end
  
  installer = Installer.new(@options)
  installer.install(script)
end

#usageObject



31
32
33
# File 'lib/vimget/commands/install_command.rb', line 31

def usage
  "#{@program_name} [NAME]"
end