Class: Kerplutz::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/kerplutz/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, desc, arguments = {}) ⇒ Command

Returns a new instance of Command.



10
11
12
13
14
15
# File 'lib/kerplutz/command.rb', line 10

def initialize(name, desc, arguments={})
  @name      = name
  @desc      = desc
  @arguments = arguments
  @parser    = OptionParser.new(default_banner)
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



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

def arguments
  @arguments
end

#descObject (readonly)

Returns the value of attribute desc.



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

def desc
  @desc
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#parserObject (readonly)

Returns the value of attribute parser.



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

def parser
  @parser
end

Instance Method Details

#add_option(option, prefix_key = true) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kerplutz/command.rb', line 25

def add_option(option, prefix_key=true)
  if prefix_key
    key = :"#{name}_#{option.name}"
  else
    key = option.name.to_sym
  end

  option.configure(parser) do |value|
    arguments[key] = value
  end
end

#banner=(banner) ⇒ Object



21
22
23
# File 'lib/kerplutz/command.rb', line 21

def banner=(banner)
  parser.banner = (banner.chomp << "\n\n")
end

#display_nameObject



17
18
19
# File 'lib/kerplutz/command.rb', line 17

def display_name
  @display_name ||= name.to_s.tr("_", "-")
end