-
Notifications
You must be signed in to change notification settings - Fork 17
/
updates_show.go
46 lines (41 loc) · 1.09 KB
/
updates_show.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 devices
import (
"fmt"
"strings"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/foundriesio/fioctl/subcommands"
)
func init() {
updatesCmd.AddCommand(&cobra.Command{
Use: "show <name> <update-id>",
Short: "[DEPRECATED] Please use: fioctl devices updates <device> <update-id>",
Hidden: true,
Run: doShowUpdate,
Args: cobra.ExactArgs(2),
})
}
func doShowUpdate(cmd *cobra.Command, args []string) {
factory := viper.GetString("factory")
logrus.Debug("Showing device update")
events, err := api.DeviceUpdateEvents(factory, args[0], args[1])
subcommands.DieNotNil(err)
for _, event := range events {
fmt.Printf("%s : %s(%s)", event.Time, event.Type.Id, event.Detail.TargetName)
if event.Detail.Success != nil {
if *event.Detail.Success {
fmt.Println(" -> Succeed")
} else {
fmt.Println(" -> Failed!")
}
} else {
fmt.Println()
}
if len(event.Detail.Details) > 0 {
fmt.Println(" Details:")
indented := " | " + strings.Replace(event.Detail.Details, "\n", "\n | ", -1)
fmt.Println(indented)
}
}
}