Class: Cmdlib::Command

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

Overview

Class for create command object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



14
15
16
17
18
19
20
21
22
# File 'lib/cmdlib/command.rb', line 14

def initialize
  @name  = ''
  @brief = ''
  @details = []
  @example = []
  @options = {}
  @subcmd  = []
  @argnum  = 0
end

Instance Attribute Details

#argnumObject

Mandatory argument numbers for command.



12
13
14
# File 'lib/cmdlib/command.rb', line 12

def argnum
  @argnum
end

#briefObject

Contain object with describe text.



6
7
8
# File 'lib/cmdlib/command.rb', line 6

def brief
  @brief
end

#detailsObject

Contain object with describe text.



6
7
8
# File 'lib/cmdlib/command.rb', line 6

def details
  @details
end

#exampleObject

Contain object with describe text.



6
7
8
# File 'lib/cmdlib/command.rb', line 6

def example
  @example
end

#nameObject

Contain object with describe text.



6
7
8
# File 'lib/cmdlib/command.rb', line 6

def name
  @name
end

#optionsObject

List with options for command and subcommand.



9
10
11
# File 'lib/cmdlib/command.rb', line 9

def options
  @options
end

#subcmdObject

List with options for command and subcommand.



9
10
11
# File 'lib/cmdlib/command.rb', line 9

def subcmd
  @subcmd
end

Instance Method Details

#addcmd(cmd) ⇒ Object

Raises:

  • (TypeError)


38
39
40
41
42
43
# File 'lib/cmdlib/command.rb', line 38

def addcmd ( cmd )
  raise TypeError, 'Incorrectly types for command object.' unless
	cmd.is_a? Cmdlib::Command

  @subcmd << cmd
end

#addopt(opt) ⇒ Object

Raises:

  • (TypeError)


31
32
33
34
35
36
# File 'lib/cmdlib/command.rb', line 31

def addopt ( opt )
  raise TypeError, 'Incorrectly types for option object.' unless
	opt.instance_of? Cmdlib::Option
	
  @options[opt.longname.to_sym] = opt
end

#handler(global_options, args) ⇒ Object



27
28
29
# File 'lib/cmdlib/command.rb', line 27

def handler( global_options, args )
  puts "error: handler do not set for this command."
end

#initObject



24
25
# File 'lib/cmdlib/command.rb', line 24

def init
end