Class: Aid::Script

Inherits:
Object
  • Object
show all
Includes:
Colorize, Inheritable
Defined in:
lib/aid/script.rb

Constant Summary

Constants included from Colorize

Colorize::COLOR_CODES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inheritable

included

Methods included from Colorize

#colorize, included

Constructor Details

#initialize(*argv) ⇒ Script

Returns a new instance of Script.



50
51
52
# File 'lib/aid/script.rb', line 50

def initialize(*argv)
  @argv = *argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



48
49
50
# File 'lib/aid/script.rb', line 48

def argv
  @argv
end

Class Method Details

.descriptionObject



36
37
38
# File 'lib/aid/script.rb', line 36

def self.description
  ""
end

.helpObject



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
    Help has not been implemented for "#{name}". Please implement a
    help method like so:

    class #{self} < Aid::Script
      def self.help
        <<-EOF
        My awesome help message here.
        This will be so useful for people.
        EOF
      end
    end
  HELP
end

.nameObject



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



54
55
56
# File 'lib/aid/script.rb', line 54

def self.run(*argv)
  new(*argv).run
end

Instance Method Details

#descriptionObject



44
45
46
# File 'lib/aid/script.rb', line 44

def description
  self.class.description
end

#exit_codeObject



62
63
64
# File 'lib/aid/script.rb', line 62

def exit_code
  0
end

#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

#helpObject



40
41
42
# File 'lib/aid/script.rb', line 40

def help
  self.class.help
end

#runObject

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/aid/script.rb', line 58

def run
  raise NotImplementedError
end

#step(name) ⇒ Object



71
72
73
74
# File 'lib/aid/script.rb', line 71

def step(name)
  puts colorize(:info, "\n== #{name} ==")
  yield if block_given?
end

#system!(*args) ⇒ Object



66
67
68
69
# File 'lib/aid/script.rb', line 66

def system!(*args)
  puts colorize(:command, args.join(" "))
  system(*args) || abort(colorize(:error, "\n== Command #{args} failed =="))
end