forked from stelligent/mu
/
environment_list.go
43 lines (32 loc) · 1009 Bytes
/
environment_list.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
36
37
38
39
40
41
42
43
package workflows
import (
"fmt"
"io"
"github.com/stelligent/mu/common"
)
// NewEnvironmentLister create a new workflow for listing environments
func NewEnvironmentLister(ctx *common.Context, writer io.Writer) Executor {
workflow := new(environmentWorkflow)
return newPipelineExecutor(
workflow.environmentLister(ctx.Config.Namespace, ctx.StackManager, writer),
)
}
func (workflow *environmentWorkflow) environmentLister(namespace string, stackLister common.StackLister, writer io.Writer) Executor {
return func() error {
stacks, err := stackLister.ListStacks(common.StackTypeEnv, namespace)
if err != nil {
return err
}
table := CreateTableSection(writer, EnvironmentShowHeader)
for _, stack := range stacks {
table.Append([]string{
Bold(stack.Tags[EnvTagKey]),
stack.Name,
fmt.Sprintf(KeyValueFormat, colorizeStackStatus(stack.Status), stack.StatusReason),
stack.LastUpdateTime.Local().Format(LastUpdateTime),
})
}
table.Render()
return nil
}
}