-
Notifications
You must be signed in to change notification settings - Fork 239
/
apps.go
72 lines (58 loc) · 1.66 KB
/
apps.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
// Package apps implements the apps command chain.
package apps
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/agent"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/flaps"
"github.com/superfly/flyctl/internal/command"
)
// New initializes and returns a new apps Command.
func New() *cobra.Command {
const (
long = `The APPS commands focus on managing your Fly applications.
Start with the CREATE command to register your application.
The LIST command will list all currently registered applications.
`
short = "Manage apps"
)
// TODO: list should also accept the --org param
// TODO: list should also accept the --platform param
apps := command.New("apps", short, long, nil)
apps.Aliases = []string{"app"}
apps.AddCommand(
newList(),
newCreate(),
newDestroy(),
newRestart(),
newMove(),
newResume(),
newSuspend(),
NewOpen(),
NewReleases(),
newErrors(),
)
return apps
}
// BuildContext is a helper that builds out commonly required context requirements
func BuildContext(ctx context.Context, app *api.AppCompact) (context.Context, error) {
client := client.FromContext(ctx).API()
agentclient, err := agent.Establish(ctx, client)
if err != nil {
return nil, fmt.Errorf("can't establish agent %w", err)
}
dialer, err := agentclient.Dialer(ctx, app.Organization.Slug)
if err != nil {
return nil, fmt.Errorf("can't build tunnel for %s: %s", app.Organization.Slug, err)
}
ctx = agent.DialerWithContext(ctx, dialer)
flapsClient, err := flaps.New(ctx, app)
if err != nil {
return nil, err
}
ctx = flaps.NewContext(ctx, flapsClient)
return ctx, nil
}