-
Notifications
You must be signed in to change notification settings - Fork 224
/
list.go
52 lines (43 loc) · 1.11 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
52
package ips
import (
"context"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/render"
"github.com/superfly/flyctl/iostreams"
)
func newList() *cobra.Command {
const (
long = `Lists the IP addresses allocated to the application`
short = `List allocated IP addresses`
)
cmd := command.New("list", short, long, runIPAddressesList,
command.RequireSession,
command.RequireAppName,
)
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.JSONOutput(),
)
return cmd
}
func runIPAddressesList(ctx context.Context) error {
cfg := config.FromContext(ctx)
client := client.FromContext(ctx).API()
appName := appconfig.NameFromContext(ctx)
ipAddresses, err := client.GetIPAddresses(ctx, appName)
if err != nil {
return err
}
if cfg.JSONOutput {
out := iostreams.FromContext(ctx).Out
return render.JSON(out, ipAddresses)
}
renderListTable(ctx, ipAddresses)
return nil
}