-
Notifications
You must be signed in to change notification settings - Fork 224
/
list.go
69 lines (60 loc) · 1.86 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package checks
import (
"context"
"fmt"
"sort"
fly "github.com/superfly/fly-go"
"github.com/superfly/fly-go/flaps"
"github.com/superfly/flyctl/helpers"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/flapsutil"
"github.com/superfly/flyctl/internal/format"
"github.com/superfly/flyctl/internal/render"
"github.com/superfly/flyctl/iostreams"
)
func runAppCheckList(ctx context.Context) error {
appName := appconfig.NameFromContext(ctx)
out := iostreams.FromContext(ctx).Out
nameFilter := flag.GetString(ctx, "check-name")
flapsClient, err := flapsutil.NewClientWithOptions(ctx, flaps.NewClientOpts{
AppName: appName,
})
if err != nil {
return err
}
machines, err := flapsClient.ListActive(ctx)
if err != nil {
return err
}
sort.Slice(machines, func(i, j int) bool {
return machines[i].ID < machines[j].ID
})
if config.FromContext(ctx).JSONOutput {
checks := map[string][]fly.MachineCheckStatus{}
for _, machine := range machines {
checks[machine.ID] = make([]fly.MachineCheckStatus, len(machine.Checks))
for i, check := range machine.Checks {
checks[machine.ID][i] = *check
}
}
return render.JSON(out, checks)
}
fmt.Fprintf(out, "Health Checks for %s\n", appName)
table := helpers.MakeSimpleTable(out, []string{"Name", "Status", "Machine", "Last Updated", "Output"})
table.SetRowLine(true)
for _, machine := range machines {
sort.Slice(machine.Checks, func(i, j int) bool {
return machine.Checks[i].Name < machine.Checks[j].Name
})
for _, check := range machine.Checks {
if nameFilter != "" && nameFilter != check.Name {
continue
}
table.Append([]string{check.Name, string(check.Status), machine.ID, format.RelativeTime(*check.UpdatedAt), check.Output})
}
}
table.Render()
return nil
}