From cd6fd4c81f634148520d2e125fbfb67d54a8616a Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Tue, 29 Oct 2019 12:48:36 +0100 Subject: [PATCH] Improved `service status` a bit. --- src/service/service.cr | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/service/service.cr b/src/service/service.cr index 24b640a..6f15b24 100644 --- a/src/service/service.cr +++ b/src/service/service.cr @@ -343,12 +343,22 @@ class Service end def summary - "Name: #{name}\n" + - "Environment: #{environment.name} (#{environment.type.to_s.downcase})\n" + + "%-16s #{name.colorize(:white).to_s}\n" % "Name:" + + "%-16s #{environment.name.colorize(:white).to_s} (#{environment.type.to_s.downcase})\n" % "Environment:" + ( if provides.size > 0 "Provides:\n" + - (provides.map { |x| " - " + x.token + "\n" }).join + (provides.map { |x| + consumers = get_consumers(x.token) + + consumers_string = if consumers.size > 0 + consumers.map(&.full_id.colorize(:green).to_s).join ", " + else + "n/a".colorize(:yellow).to_s + end + + " - %-12s #{consumers_string}\n" % "#{x.token}:" + }).join else "" end @@ -358,13 +368,26 @@ class Service "Consumes:\n" + (@reference.consumes.map { |x| provider = @providers[x.token]? - if provider - " - #{x.token} (from #{provider.id})\n" + + provider_string = if provider + provider.full_id.colorize(:green).to_s + elsif x.optional + "n/a".colorize(:yellow).to_s else - " - #{x.token} " + - "(NOT CURRENTLY PROVIDED)".colorize(:red).to_s + - "\n" + "MISSING".colorize(:red).to_s end + + " - %-12s #{provider_string}\n" % x.token + }).join + else + "" + end + ) + + ( + if @ports.size > 0 + "Ports:\n" + + (@ports.map { |name, number| + " - %-12s #{number.colorize(:magenta).to_s}\n" % "#{name}:" }).join else ""