-
Notifications
You must be signed in to change notification settings - Fork 240
/
apps.go
93 lines (72 loc) · 3.25 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package cmd
import (
"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/internal/client"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/cmd/presenters"
"github.com/superfly/flyctl/docstrings"
)
func newAppsCommand(client *client.Client) *Command {
appsStrings := docstrings.Get("apps")
cmd := &Command{
Command: &cobra.Command{
Use: appsStrings.Usage,
Short: appsStrings.Short,
Long: appsStrings.Long,
},
}
appsListStrings := docstrings.Get("apps.list")
BuildCommand(cmd, runAppsList, appsListStrings.Usage, appsListStrings.Short, appsListStrings.Long, client, requireSession)
appsCreateStrings := docstrings.Get("apps.create")
create := BuildCommand(cmd, runInit, appsCreateStrings.Usage, appsCreateStrings.Short, appsCreateStrings.Long, client, requireSession)
create.Args = cobra.RangeArgs(0, 1)
// TODO: Move flag descriptions into the docStrings
create.AddStringFlag(StringFlagOpts{
Name: "name",
Description: "The app name to use",
})
create.AddStringFlag(StringFlagOpts{
Name: "org",
Description: `The organization that will own the app`,
})
create.AddStringFlag(StringFlagOpts{
Name: "port",
Shorthand: "p",
Description: "Internal port on application to connect to external services",
})
create.AddStringFlag(StringFlagOpts{
Name: "builder",
Description: `The Cloud Native Buildpacks builder to use when deploying the app`,
})
appsDestroyStrings := docstrings.Get("apps.destroy")
destroy := BuildCommand(cmd, runDestroy, appsDestroyStrings.Usage, appsDestroyStrings.Short, appsDestroyStrings.Long, client, requireSession)
destroy.Args = cobra.ExactArgs(1)
// TODO: Move flag descriptions into the docStrings
destroy.AddBoolFlag(BoolFlagOpts{Name: "yes", Shorthand: "y", Description: "Accept all confirmations"})
appsMoveStrings := docstrings.Get("apps.move")
move := BuildCommand(cmd, runMove, appsMoveStrings.Usage, appsMoveStrings.Short, appsMoveStrings.Long, client, requireSession)
move.Args = cobra.ExactArgs(1)
// TODO: Move flag descriptions into the docStrings
move.AddBoolFlag(BoolFlagOpts{Name: "yes", Shorthand: "y", Description: "Accept all confirmations"})
move.AddStringFlag(StringFlagOpts{
Name: "org",
Description: `The organization to move the app to`,
})
appsSuspendStrings := docstrings.Get("apps.suspend")
appsSuspendCmd := BuildCommand(cmd, runSuspend, appsSuspendStrings.Usage, appsSuspendStrings.Short, appsSuspendStrings.Long, client, requireSession, requireAppNameAsArg)
appsSuspendCmd.Args = cobra.RangeArgs(0, 1)
appsResumeStrings := docstrings.Get("apps.resume")
appsResumeCmd := BuildCommand(cmd, runResume, appsResumeStrings.Usage, appsResumeStrings.Short, appsResumeStrings.Long, client, requireSession, requireAppNameAsArg)
appsResumeCmd.Args = cobra.RangeArgs(0, 1)
appsRestartStrings := docstrings.Get("apps.restart")
appsRestartCmd := BuildCommand(cmd, runRestart, appsRestartStrings.Usage, appsRestartStrings.Short, appsRestartStrings.Long, client, requireSession, requireAppNameAsArg)
appsRestartCmd.Args = cobra.RangeArgs(0, 1)
return cmd
}
func runAppsList(ctx *cmdctx.CmdContext) error {
listapps, err := ctx.Client.API().GetApps(nil)
if err != nil {
return err
}
return ctx.Render(&presenters.Apps{Apps: listapps})
}