Class: VimGet::CommandManager

Inherits:
Object
  • Object
show all
Defined in:
lib/vimget/command_manager.rb

Overview

This class will find property command and invoke it

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject

singleton entry



19
20
21
# File 'lib/vimget/command_manager.rb', line 19

def self.instance
  @command_manager ||= CommandManager.new
end

Instance Method Details

#help(cmd = "") ⇒ Object

display special help informations for command



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/vimget/command_manager.rb', line 91

def help(cmd="")
  if cmd.empty? 
    usage
  elsif cmd == "help"
    nil
  else
    command_obj = find_command(cmd)
    command_obj.show_help
  end
  
  exit 1
end

#process_args(args) ⇒ Object

handle arguments for special command



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

def process_args(args)
  if ARGV.empty?
    usage
    exit 1
  end
  
  case ARGV[0]
  when '-h', '--help'
    usage
    exit 1
  when '-v', '--version', 'version'
    version
  when 'help'
    ARGV[1] ? help(ARGV[1]) : help
  end
  
  cmd_obj = find_command(ARGV[0])
  cmd_obj.invoke(ARGV.dup)
end

#run(args) ⇒ Object

run the command manager with args

  • args is a argument array



25
26
27
28
29
30
31
32
33
# File 'lib/vimget/command_manager.rb', line 25

def run(args)
  process_args(args)
rescue StandardError => ex
  puts "While execute vim-get...(#{ex.class})\n   #{ex.to_s}"
  puts ex.backtrace if VimGet.configure.debug
rescue Interrupt
  puts "Interrupt"
  exit 1
end

#usageObject

display general usage



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vimget/command_manager.rb', line 57

def usage
  puts <<-USAGE 
  vim-get: the vim script management tool

  Usage: 
    vim-get -h/--help    
    vim-get -v/--version 
    vim-get command [options] [arg1 argu2 ...]

  Common options:
    --debug         display debug infomation
    --verbose       set verbose

  Supported commands:
    help            provide help for special commands
    version         display version and runtime informations

    install         install a script
    uninstall       uninstall a script
    upgrade         upgrade outdated script
    sync            sync local script version database
    clean           clean all distributed files

    list            list local scripts
    outdated        list all outdated scripts
    installed       list all installed scripts

  Further Infomation:
    https://rubyforge.org/projects/vimget/

  USAGE
end

#versionObject

puts version and runtime info



105
106
107
108
109
110
111
112
# File 'lib/vimget/command_manager.rb', line 105

def version
  puts "vim-get: vim script management tool #{VIMGET_VERSION}"
  puts
  puts "Runtime:"
  puts "  vim-get base dir: #{VimGet.configure.base_dir}"
  puts "  vim dir: #{VimGet.configure.vim_dir}"
  exit 1
end