-
Notifications
You must be signed in to change notification settings - Fork 223
/
apps.go
73 lines (59 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
73
// Package apps implements the apps command chain.
package apps
import (
"context"
"fmt"
"github.com/spf13/cobra"
fly "github.com/superfly/fly-go"
"github.com/superfly/fly-go/flaps"
"github.com/superfly/flyctl/agent"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flapsutil"
"github.com/superfly/flyctl/internal/flyutil"
)
// New initializes and returns a new apps Command.
func New() *cobra.Command {
const (
long = "Manage your Fly 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 *fly.AppCompact) (context.Context, error) {
client := flyutil.ClientFromContext(ctx)
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 := flapsutil.NewClientWithOptions(ctx, flaps.NewClientOpts{
AppCompact: app,
AppName: app.Name,
})
if err != nil {
return nil, err
}
ctx = flapsutil.NewContextWithClient(ctx, flapsClient)
return ctx, nil
}