Class: VimGet::BaseCommand
- Inherits:
-
Object
- Object
- VimGet::BaseCommand
- Defined in:
- lib/vimget/command.rb
Overview
base class for all commands, providing fundamental functions for command
Direct Known Subclasses
Commands::CleanCommand, Commands::InstallCommand, Commands::ListCommand, Commands::SyncCommand, Commands::UninstallCommand, Commands::UpgradeCommand
Constant Summary collapse
- PROGRAM =
"vim-get"
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
the name of command.
-
#defaults ⇒ Object
the default options for the command.
-
#options ⇒ Object
readonly
the options for this command.
-
#options_group ⇒ Object
readonly
divide options into named groups.
-
#program_name ⇒ Object
the name of the command for command-line invocation.
-
#summary ⇒ Object
A short description of the command.
Instance Method Summary collapse
-
#arguments ⇒ Object
return a argument string.
-
#execute ⇒ Object
interface for all sub class, must implement this function!.
-
#initialize(command, summary = nil, defaults = {}) ⇒ BaseCommand
constructor
A new instance of BaseCommand.
- #invoke(*args) ⇒ Object
- #show_help ⇒ Object
- #usage ⇒ Object
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
#command ⇒ Object (readonly)
the name of command
22 23 24 |
# File 'lib/vimget/command.rb', line 22 def command @command end |
#defaults ⇒ Object
the default options for the command
31 32 33 |
# File 'lib/vimget/command.rb', line 31 def defaults @defaults end |
#options ⇒ Object (readonly)
the options for this command
25 26 27 |
# File 'lib/vimget/command.rb', line 25 def @options end |
#options_group ⇒ Object (readonly)
divide options into named groups
28 29 30 |
# File 'lib/vimget/command.rb', line 28 def @options_group end |
#program_name ⇒ Object
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 |
#summary ⇒ Object
A short description of the command
37 38 39 |
# File 'lib/vimget/command.rb', line 37 def summary @summary end |
Instance Method Details
#arguments ⇒ Object
return a argument string
57 58 59 |
# File 'lib/vimget/command.rb', line 57 def arguments "" end |
#execute ⇒ Object
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) (args) if @options[:help] show_help else execute end end |
#show_help ⇒ Object
51 52 53 54 |
# File 'lib/vimget/command.rb', line 51 def show_help parser.program_name = usage puts @parser end |
#usage ⇒ Object
47 48 49 |
# File 'lib/vimget/command.rb', line 47 def usage @program_name end |