forked from cloudfoundry/cli
/
packages_command.go
79 lines (63 loc) · 1.79 KB
/
packages_command.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 v7
import (
"strings"
"time"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/util/ui"
)
type PackagesCommand struct {
BaseCommand
RequiredArgs flag.AppName `positional-args:"yes"`
usage interface{} `usage:"CF_NAME packages APP_NAME"`
relatedCommands interface{} `related_commands:"droplets, create-package, app, push"`
}
func (cmd PackagesCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, true)
if err != nil {
return err
}
user, err := cmd.Actor.GetCurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Getting packages of app {{.AppName}} in org {{.CurrentOrg}} / space {{.CurrentSpace}} as {{.CurrentUser}}...", map[string]interface{}{
"AppName": cmd.RequiredArgs.AppName,
"CurrentSpace": cmd.Config.TargetedSpace().Name,
"CurrentOrg": cmd.Config.TargetedOrganization().Name,
"CurrentUser": user.Name,
})
cmd.UI.DisplayNewline()
packages, warnings, err := cmd.Actor.GetApplicationPackages(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
if len(packages) == 0 {
cmd.UI.DisplayText("No packages found.")
return nil
}
contents := [][]string{}
for _, pkg := range packages {
t, err := time.Parse(time.RFC3339, pkg.CreatedAt)
if err != nil {
return err
}
contents = append(contents, []string{
pkg.GUID,
cmd.UI.TranslateText(strings.ToLower(string(pkg.State))),
cmd.UI.UserFriendlyDate(t),
})
}
table := [][]string{
{
cmd.UI.TranslateText("guid"),
cmd.UI.TranslateText("state"),
cmd.UI.TranslateText("created"),
},
}
for _, p := range contents {
table = append(table, p)
}
cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding)
return nil
}