-
Notifications
You must be signed in to change notification settings - Fork 24
/
list.go
51 lines (43 loc) · 1.01 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
package deployments
import (
"fmt"
"os"
"time"
"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/utils"
"github.com/olekukonko/tablewriter"
"gopkg.in/errgo.v1"
)
func List(app string) error {
c, err := config.ScalingoClient()
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
}
deployments, err := c.DeploymentList(app)
if err != nil {
return errgo.Mask(err)
}
if len(deployments) == 0 {
} else {
t := tablewriter.NewWriter(os.Stdout)
t.SetHeader([]string{"ID", "Date", "Duration", "User", "Git Ref", "Status"})
for _, deployment := range deployments {
var duration string
if deployment.Duration != 0 {
d, _ := time.ParseDuration(fmt.Sprintf("%ds", deployment.Duration))
duration = d.String()
} else {
duration = "n/a"
}
t.Append([]string{deployment.ID,
deployment.CreatedAt.Format(utils.TimeFormat),
duration,
deployment.User.Username,
deployment.GitRef,
string(deployment.Status),
})
}
t.Render()
}
return nil
}