-
Notifications
You must be signed in to change notification settings - Fork 218
/
history.go
79 lines (65 loc) · 1.64 KB
/
history.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
70
71
72
73
74
75
76
77
78
79
// Package history implements the history command chain.
package history
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/format"
"github.com/superfly/flyctl/internal/render"
)
func New() (cmd *cobra.Command) {
const (
long = `List the history of changes in the application. Includes autoscaling
events and their results.
`
short = "List an app's change history"
)
cmd = command.New("history", short, long, run,
command.RequireSession,
command.RequireAppName,
)
cmd.Deprecated = "Use `flyctl apps releases` instead"
cmd.Hidden = true
cmd.Args = cobra.NoArgs
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.JSONOutput(),
)
return
}
func run(ctx context.Context) error {
appName := appconfig.NameFromContext(ctx)
client := client.FromContext(ctx).API()
changes, err := client.GetAppChanges(ctx, appName)
if err != nil {
return fmt.Errorf("failed retrieving history for %s: %w", appName, err)
}
out := iostreams.FromContext(ctx).Out
if config.FromContext(ctx).JSONOutput {
return render.JSON(out, changes)
}
var rows [][]string
for _, change := range changes {
rows = append(rows, []string{
change.Actor.Type,
change.Status,
change.Description,
change.User.Email,
format.RelativeTime(change.CreatedAt),
})
}
return render.Table(out, "", rows,
"Type",
"Status",
"Description",
"User",
"Date",
)
}