Class: Cerberus::StatusCommand
- Inherits:
-
Object
- Object
- Cerberus::StatusCommand
- Defined in:
- lib/cerberus/manager.rb
Instance Method Summary collapse
- #ansi_escape(code, str) ⇒ Object
- #ansi_green(str) ⇒ Object
- #ansi_red(str) ⇒ Object
-
#initialize(cli_options = {}) ⇒ StatusCommand
constructor
A new instance of StatusCommand.
- #run ⇒ Object
Constructor Details
#initialize(cli_options = {}) ⇒ StatusCommand
Returns a new instance of StatusCommand.
238 239 |
# File 'lib/cerberus/manager.rb', line 238 def initialize( = {}) end |
Instance Method Details
#ansi_escape(code, str) ⇒ Object
274 275 276 |
# File 'lib/cerberus/manager.rb', line 274 def ansi_escape(code, str) "\033[#{code}" + str + "\033[0m" end |
#ansi_green(str) ⇒ Object
266 267 268 |
# File 'lib/cerberus/manager.rb', line 266 def ansi_green(str) ansi_escape('32m', str) end |
#ansi_red(str) ⇒ Object
270 271 272 |
# File 'lib/cerberus/manager.rb', line 270 def ansi_red(str) ansi_escape('31m', str) end |
#run ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/cerberus/manager.rb', line 241 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 |