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.



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

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

Instance Method Details

#argumentsObject



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

def arguments
  "NAME    name of script to install"
end

#executeObject



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

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
    script_name = fetch_one_argu
    if script_name.nil?
      raise CommandLineError, "You must indicate one script to install."
    end
    script = VimGet.db.find(script_name)
    
    raise UnknownScriptError, "Unknow script! (Perhaps you need install it by indicate its id)" if script.nil?
  end
  
  installer = Installer.new(@options)
  installer.install(script)
end

#usageObject



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

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