-
Notifications
You must be signed in to change notification settings - Fork 16
/
list.go
46 lines (40 loc) · 1.14 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
package waves
import (
"github.com/cheynewallace/tabby"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/foundriesio/fioctl/subcommands"
)
func init() {
listCmd := &cobra.Command{
Use: "list",
Short: "Show available waves",
Run: doListWaves,
}
cmd.AddCommand(listCmd)
listCmd.Flags().Uint64P("limit", "n", 20, "Limit the number of results displayed.")
listCmd.Flags().IntP("page", "p", 1, "Page of waves to display when pagination is needed")
}
func doListWaves(cmd *cobra.Command, args []string) {
factory := viper.GetString("factory")
limit, _ := cmd.Flags().GetUint64("limit")
showPage, _ := cmd.Flags().GetInt("page")
logrus.Debugf("Showing a list of waves for %s", factory)
lst, err := api.FactoryListWaves(factory, limit, showPage)
subcommands.DieNotNil(err)
t := tabby.New()
t.AddHeader("NAME", "VERSION", "TAG", "STATUS", "CREATED AT", "FINISHED AT")
for _, wave := range lst.Waves {
t.AddLine(
wave.Name,
wave.Version,
wave.Tag,
wave.Status,
wave.ChangeMeta.CreatedAt,
wave.ChangeMeta.UpdatedAt,
)
}
t.Print()
subcommands.ShowPages(showPage, lst.Next)
}