Class: Aid::Script
Constant Summary
Constants included
from Colorize
Colorize::COLOR_CODES
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Methods included from Colorize
#colorize, included
Constructor Details
#initialize(*argv) ⇒ Script
Returns a new instance of Script.
42
43
44
|
# File 'lib/aid/script.rb', line 42
def initialize(*argv)
@argv = *argv
end
|
Instance Attribute Details
#argv ⇒ Object
Returns the value of attribute argv.
40
41
42
|
# File 'lib/aid/script.rb', line 40
def argv
@argv
end
|
Class Method Details
.description ⇒ Object
36
37
38
|
# File 'lib/aid/script.rb', line 36
def self.description
""
end
|
.help ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/aid/script.rb', line 20
def self.help
" Help has not been implemented for \"\#{name}\". Please implement a\n help method like so:\n\n class \#{self} < Aid::Script\n def self.help\n <<-EOF\n My awesome help message here.\n This will be so useful for people.\n EOF\n end\n end\n HELP\nend\n"
|
.name ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/aid/script.rb', line 6
def self.name
klass_name = self.to_s.split('::').last
klass_name
.scan(/[A-Z][a-z0-9]*/)
.map(&:downcase)
.join('-')
end
|
.run(*argv) ⇒ Object
46
47
48
|
# File 'lib/aid/script.rb', line 46
def self.run(*argv)
new(*argv).run
end
|
Instance Method Details
#exit_with_help! ⇒ Object
15
16
17
18
|
# File 'lib/aid/script.rb', line 15
def exit_with_help!
puts self.class.help
exit
end
|
#run ⇒ Object
50
51
52
|
# File 'lib/aid/script.rb', line 50
def run
raise NotImplementedError
end
|
#step(name) ⇒ Object
59
60
61
62
|
# File 'lib/aid/script.rb', line 59
def step(name)
puts colorize(:info, "\n== #{name} ==")
yield if block_given?
end
|
#system!(*args) ⇒ Object
54
55
56
57
|
# File 'lib/aid/script.rb', line 54
def system!(*args)
puts colorize(:command, args.join(" "))
system(*args) || abort(colorize(:error, "\n== Command #{args} failed =="))
end
|