-
Notifications
You must be signed in to change notification settings - Fork 223
/
resume.go
48 lines (36 loc) · 1.06 KB
/
resume.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
package cmd
import (
"fmt"
"os"
"time"
"github.com/briandowns/spinner"
"github.com/superfly/flyctl/cmdctx"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/docstrings"
)
//TODO: Move all output to status styled begin/done updates
func newResumeCommand() *Command {
resumeStrings := docstrings.Get("resume")
resumeCmd := BuildCommandKS(nil, runResume, resumeStrings, os.Stdout, requireSession, requireAppNameAsArg)
resumeCmd.Args = cobra.RangeArgs(0, 1)
return resumeCmd
}
func runResume(cmdctx *cmdctx.CmdContext) error {
app, err := cmdctx.Client.API().ResumeApp(cmdctx.AppName)
if err != nil {
return err
}
s := spinner.New(spinner.CharSets[11], 100*time.Millisecond)
s.Writer = os.Stderr
s.Prefix = fmt.Sprintf("Resuming %s with 1 instance to start ", cmdctx.AppName)
s.Start()
for app.Status != "running" {
app, err = cmdctx.Client.API().GetApp(cmdctx.AppName)
if err != nil {
return err
}
}
s.FinalMSG = fmt.Sprintf("Resume complete - %s is now %s with 1 running instance\n", cmdctx.AppName, app.Status)
s.Stop()
return nil
}