Class: VimGet::BaseCommand

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

Overview

base class for all commands, providing fundamental functions for command

Constant Summary collapse

PROGRAM =
"vim-get"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, summary = nil, defaults = {}) ⇒ BaseCommand

Returns a new instance of BaseCommand.



39
40
41
42
43
44
45
# File 'lib/vimget/command.rb', line 39

def initialize(command, summary = nil, defaults = {})
  @command, @summary, @defaults = command, summary, defaults
  @program_name = "#{PROGRAM} #{command}"
  @options = defaults.dup
  @parser = nil
  @option_groups = Hash.new { |h,k| h[k] = [] }
end

Instance Attribute Details

#commandObject (readonly)

the name of command



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

def command
  @command
end

#defaultsObject

the default options for the command



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

def defaults
  @defaults
end

#optionsObject (readonly)

the options for this command



25
26
27
# File 'lib/vimget/command.rb', line 25

def options
  @options
end

#options_groupObject (readonly)

divide options into named groups



28
29
30
# File 'lib/vimget/command.rb', line 28

def options_group
  @options_group
end

#program_nameObject

the name of the command for command-line invocation



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

def program_name
  @program_name
end

#summaryObject

A short description of the command



37
38
39
# File 'lib/vimget/command.rb', line 37

def summary
  @summary
end

Instance Method Details

#argumentsObject

return a argument string



57
58
59
# File 'lib/vimget/command.rb', line 57

def arguments
  ""
end

#executeObject

interface for all sub class, must implement this function!



71
72
73
# File 'lib/vimget/command.rb', line 71

def execute
  raise 'Command without define execute function'
end

#invoke(*args) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/vimget/command.rb', line 61

def invoke(*args)
  handle_options(args)
  if @options[:help]
    show_help
  else
    execute
  end
end

#show_helpObject



51
52
53
54
# File 'lib/vimget/command.rb', line 51

def show_help
  parser.program_name = usage
  puts @parser
end

#usageObject



47
48
49
# File 'lib/vimget/command.rb', line 47

def usage
  @program_name
end