Class: Bow::Command
- Inherits:
-
Object
show all
- Defined in:
- lib/bow/command.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(app = nil, argv = []) ⇒ Command
Returns a new instance of Command.
37
38
39
40
|
# File 'lib/bow/command.rb', line 37
def initialize(app = nil, argv = [])
@app = app
@argv = argv
end
|
Class Attribute Details
.all ⇒ Object
Returns the value of attribute all.
8
9
10
|
# File 'lib/bow/command.rb', line 8
def all
@all
end
|
.names ⇒ Object
Returns the value of attribute names.
8
9
10
|
# File 'lib/bow/command.rb', line 8
def names
@names
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
35
36
37
|
# File 'lib/bow/command.rb', line 35
def app
@app
end
|
Class Method Details
.command_name ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/bow/command.rb', line 17
def command_name
@command_name ||= name.to_s
.split('::')
.last
.split(/([A-Z]{1}[^A-Z]*)/)
.reject(&:empty?)
.join('_')
.downcase
end
|
.find(name) ⇒ Object
27
28
29
30
|
# File 'lib/bow/command.rb', line 27
def find(name)
index = @names.index name.to_s
@all[index] if index
end
|
.inherited(command_class) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/bow/command.rb', line 10
def inherited(command_class)
@all ||= []
@names ||= []
@all << command_class
@names << command_class.command_name
end
|
Instance Method Details
#command_name ⇒ Object
50
51
52
|
# File 'lib/bow/command.rb', line 50
def command_name
self.class.command_name
end
|
#description ⇒ Object
42
43
44
|
# File 'lib/bow/command.rb', line 42
def description
@description ||= "Command #{command_name} description"
end
|
#targets ⇒ Object
54
55
56
57
58
|
# File 'lib/bow/command.rb', line 54
def targets
user = app.options[:user]
group = app.options[:group]
app.targets(user).hosts(group)
end
|
#usage ⇒ Object
46
47
48
|
# File 'lib/bow/command.rb', line 46
def usage
@usage ||= "bow #{command_name} [args] [options]"
end
|