-
Notifications
You must be signed in to change notification settings - Fork 240
/
instances.go
62 lines (46 loc) · 1.21 KB
/
instances.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
package agent
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/agent"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/iostreams"
apiClient "github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/render"
)
func newInstances() (cmd *cobra.Command) {
const (
short = "List instances"
long = short + "\n"
usage = "instances <slug> <app>"
)
cmd = command.New(usage, short, long, runInstances,
command.RequireSession,
)
cmd.Args = cobra.ExactArgs(2)
return
}
func runInstances(ctx context.Context) (err error) {
var client *agent.Client
if client, err = establish(ctx); err != nil {
return
}
slug := flag.FirstArg(ctx)
apiClient := apiClient.FromContext(ctx).API()
var org *api.Organization
if org, err = apiClient.GetOrganizationBySlug(ctx, slug); err != nil {
err = fmt.Errorf("failed fetching org: %w", err)
return
}
app := flag.Args(ctx)[1]
var instances agent.Instances
if instances, err = client.Instances(ctx, org.Slug, app); err != nil {
return
}
out := iostreams.FromContext(ctx).Out
err = render.JSON(out, instances)
return
}