Class: Cerberus::StatusCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/cerberus/manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(cli_options = {}) ⇒ StatusCommand

Returns a new instance of StatusCommand.



236
237
# File 'lib/cerberus/manager.rb', line 236

def initialize(cli_options = {})                                                                             
end

Instance Method Details

#ansi_escape(code, str) ⇒ Object



272
273
274
# File 'lib/cerberus/manager.rb', line 272

def ansi_escape(code, str)
  "\033[#{code}" + str + "\033[0m"
end

#ansi_green(str) ⇒ Object



264
265
266
# File 'lib/cerberus/manager.rb', line 264

def ansi_green(str)
  ansi_escape('32m', str)
end

#ansi_red(str) ⇒ Object



268
269
270
# File 'lib/cerberus/manager.rb', line 268

def ansi_red(str)
  ansi_escape('31m', str)
end

#runObject



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/cerberus/manager.rb', line 239

def run
  projects = Dir["#{HOME}/config/*.yml"].sort.map { |fn| fn.gsub(/.*\/(.*).yml$/, '\1') }
  if projects.empty?
    puts "There are not any active projects" 
  else
    delim = ' | '
    cols  = [
      ['Project Name', 30, lambda { |p, s| p }],
      ['Revision',     10, lambda { |p, s| "#{s.revision.to_s.slice( 0, 8 ) }"}],
      ['Status',       10, lambda { |p, s| s.previous_build_successful ? 'Pass' : 'Fail' }],
      ['Last Success', 10, lambda { |p, s| "#{s.successful_build_revision.to_s.slice( 0, 8 )}"}],
    ]
    header = cols.map { |head, size, lamb| head.ljust(size) }.join(delim)
    puts '-' * header.length
    puts header
    puts '-' * header.length
    projects.each do |proj|
      status = Status.read("#{HOME}/work/#{proj}/status.log")
      row    = cols.map { |head, size, lamb| lamb.call(proj, status).to_s.ljust(size) }.join(delim)
      puts status.previous_build_successful ? ansi_green(row) : ansi_red(row)
    end
    puts '-' * header.length
  end
end