-
Notifications
You must be signed in to change notification settings - Fork 221
/
info.go
70 lines (56 loc) · 1.83 KB
/
info.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
package cmd
import (
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/internal/buildinfo"
"github.com/superfly/flyctl/docstrings"
"github.com/superfly/flyctl/cmd/presenters"
)
func newInfoCommand(client *client.Client) *Command {
ks := docstrings.Get("info")
appInfoCmd := BuildCommandKS(nil, runInfo, ks, client, requireSession, requireAppName)
appInfoCmd.AddBoolFlag(BoolFlagOpts{
Name: "name",
Shorthand: "n",
Description: "Returns just the appname",
})
appInfoCmd.AddBoolFlag(BoolFlagOpts{
Name: "host",
Description: "Returns just the hostname",
})
return appInfoCmd
}
func runInfo(cmdCtx *cmdctx.CmdContext) error {
ctx := cmdCtx.Command.Context()
app, err := cmdCtx.Client.API().GetAppInfo(ctx, cmdCtx.AppName)
if err != nil {
return err
}
if cmdCtx.Config.GetBool("name") {
cmdCtx.Status("info", cmdctx.SINFO, app.Name)
return nil
}
if cmdCtx.Config.GetBool("host") {
cmdCtx.Status("info", cmdctx.SINFO, app.Hostname)
return nil
}
err = cmdCtx.Frender(cmdctx.PresenterOption{Presentable: &presenters.AppInfo{AppInfo: *app}, HideHeader: true, Vertical: true, Title: "App"})
if err != nil {
return err
}
// For JSON, everything is included in the previous render, for humans, we need to do some formatting
if !cmdCtx.OutputJSON() {
err = cmdCtx.Frender(cmdctx.PresenterOption{Presentable: &presenters.Services{Services: app.Services}, Title: "Services"})
if err != nil {
return err
}
err = cmdCtx.Frender(cmdctx.PresenterOption{Presentable: &presenters.IPAddresses{IPAddresses: app.IPAddresses.Nodes}, Title: "IP Addresses"})
if err != nil {
return err
}
if !app.Deployed {
cmdCtx.Status("info", `App has not been deployed yet. Try running "`+buildinfo.Name()+` deploy --image flyio/hellofly"`)
}
}
return nil
}