-
Notifications
You must be signed in to change notification settings - Fork 239
/
restart.go
46 lines (34 loc) · 963 Bytes
/
restart.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
package apps
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
)
func newRestart() *cobra.Command {
const (
long = `The APPS RESTART command will restart all running vms.
`
short = "Restart an application"
usage = "restart [APPNAME]"
)
restart := command.New(usage, short, long, RunRestart,
command.RequireSession,
)
restart.Args = cobra.ExactArgs(1)
return restart
}
// TODO: make internal once the restart package is removed
func RunRestart(ctx context.Context) error {
client := client.FromContext(ctx).API()
appName := flag.FirstArg(ctx)
if _, err := client.RestartApp(ctx, appName); err != nil {
return fmt.Errorf("failed restarting app: %w", err)
}
io := iostreams.FromContext(ctx)
fmt.Fprintf(io.Out, "%s is being restarted\n", appName)
return nil
}