Class: Commander::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/commander-tool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description = "", &block) ⇒ Command

Returns a new instance of Command.



9
10
11
12
13
14
15
# File 'lib/commander-tool.rb', line 9

def initialize(name, description = "", &block)
  @name = name.to_s
  @description = description
  @options = []
  @subcommands = {}
  @block = block
end

Instance Attribute Details

#block ⇒ Object (readonly)

Returns the value of attribute block.



7
8
9
# File 'lib/commander-tool.rb', line 7

def block
  @block
end

#description ⇒ Object (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/commander-tool.rb', line 7

def description
  @description
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/commander-tool.rb', line 7

def name
  @name
end

#options ⇒ Object (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/commander-tool.rb', line 7

def options
  @options
end

#subcommands ⇒ Object (readonly)

Returns the value of attribute subcommands.



7
8
9
# File 'lib/commander-tool.rb', line 7

def subcommands
  @subcommands
end

Instance Method Details

#add_option(switches, description = "") ⇒ Object



17
18
19
20
# File 'lib/commander-tool.rb', line 17

def add_option(switches, description = "")
  @options << Option.new(switches, description)
  self
end

#add_subcommand(name, description = "", &block) ⇒ Object



22
23
24
25
26
# File 'lib/commander-tool.rb', line 22

def add_subcommand(name, description = "", &block)
  command = Command.new(name, description, &block)
  @subcommands[command.name] = command
  command
end

#has_subcommands? ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/commander-tool.rb', line 28

def has_subcommands?
  !@subcommands.empty?
end