Class: Pedant::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/pedant/command.rb

Direct Known Subclasses

CommandCheck, CommandTest

Class Method Summary collapse

Class Method Details

.allObject



33
34
35
# File 'lib/pedant/command.rb', line 33

def self.all
  (@_all ||= [])
end


53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pedant/command.rb', line 53

def self.banner(title, width=80)
  # Create center of banner.
  middle = "[ #{title} ]"

  # Make sure width is a float.
  width = width.to_f

  # Create bars on either side.
  leftover = (width - middle.length) / 2
  left = '-' * leftover.floor
  right = '-' * leftover.ceil

  left + middle + right
end

.find(cmd) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/pedant/command.rb', line 45

def self.find(cmd)
  all.each do |cls|
    return cls if cls.binding == cmd
  end

  nil
end

.inherited(cls) ⇒ Object



37
38
39
# File 'lib/pedant/command.rb', line 37

def self.inherited(cls)
  all << cls
end

.initialize!Object



29
30
31
# File 'lib/pedant/command.rb', line 29

def self.initialize!
  Dir.glob(Pedant.lib + 'pedant/commands/*.rb').each {|f| load(f)}
end

.listObject



41
42
43
# File 'lib/pedant/command.rb', line 41

def self.list
  all.map{ |cls| cls.binding }.sort
end

.run(opts, args) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/pedant/command.rb', line 68

def self.run(opts, args)
  # Parse the command's arguments.
  opts, args = optparse(opts, args)

  # Run the command.
  self.run_all(opts, args)
end

.usage(msg) ⇒ Object



76
77
78
79
80
81
# File 'lib/pedant/command.rb', line 76

def self.usage(msg)
  puts Rainbow(msg).color(:red)
  puts
  puts help
  exit 1
end