-
Notifications
You must be signed in to change notification settings - Fork 1
/
format.go
35 lines (31 loc) · 862 Bytes
/
format.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package stacks
import (
"fmt"
"strings"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/fatih/color"
)
func FormatStackStatus(s string) string {
switch {
case strings.HasSuffix(s, "COMPLETE") && !strings.HasPrefix(s, "DELETE"):
return color.GreenString(s)
case strings.Contains(s, "FAILED") || strings.Contains(s, "ROLLBACK"):
return color.RedString(s)
case strings.HasSuffix(s, "IN_PROGRESS"):
return color.YellowString(s)
}
return s
}
func FormatStackEvent(event *cloudformation.StackEvent) string {
descr := ""
if event.ResourceStatusReason != nil {
descr = fmt.Sprintf("=> %q", *event.ResourceStatusReason)
}
return fmt.Sprintf("%s %s -> %s [%s] %s",
event.Timestamp.Local().Format("2006/01/02 15:04:05"),
FormatStackStatus(*event.ResourceStatus),
*event.LogicalResourceId,
*event.ResourceType,
descr,
)
}