Class: Mantra::Command
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Constructor Details
#initialize(options) ⇒ Command
Returns a new instance of Command.
28
29
30
|
# File 'lib/mantra/command.rb', line 28
def initialize(options)
@args = options[:args]
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
32
33
34
|
# File 'lib/mantra/command.rb', line 32
def options
@options
end
|
Class Method Details
.option(name, long_option, short_option, description) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/mantra/command.rb', line 16
def self.option(name, long_option, short_option, description)
self.option_descriptors << [name, long_option, short_option, description]
self.send(:define_method, name) do
@options[name.to_s]
end
end
|
.option_descriptors ⇒ Object
7
8
9
|
# File 'lib/mantra/command.rb', line 7
def self.option_descriptors
@options ||= []
end
|
.usage ⇒ Object
11
12
13
14
|
# File 'lib/mantra/command.rb', line 11
def self.usage
"\n\tUsage: \tmantra <action> [options]\n" +
"\tactions:\t#{self.subclasses.map { |s| s.type }.join(", ")}\n\n"
end
|
Instance Method Details
#parse_options ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/mantra/command.rb', line 33
def parse_options
@options = {}
OptionParser.new do |options_parser|
options_parser.banner = "Usage: mantra #{} [options]"
self.class.option_descriptors.each do |option|
option_name = option.shift.to_s
options_parser.on(*option) do |value|
@options[option_name] = value
end
end
end.parse!
@options
end
|
#run ⇒ Object
23
24
25
26
|
# File 'lib/mantra/command.rb', line 23
def run
parse_options
perform
end
|