forked from sst/ion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh.go
57 lines (52 loc) · 1.01 KB
/
refresh.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
package main
import (
"strings"
"github.com/sst/ion/cmd/sst/cli"
"github.com/sst/ion/cmd/sst/mosaic/ui"
"github.com/sst/ion/pkg/bus"
"github.com/sst/ion/pkg/project"
"github.com/sst/ion/pkg/server"
"golang.org/x/sync/errgroup"
)
func CmdRefresh(c *cli.Cli) error {
p, err := c.InitProject()
if err != nil {
return err
}
defer p.Cleanup()
target := []string{}
if c.String("target") != "" {
target = strings.Split(c.String("target"), ",")
}
var wg errgroup.Group
defer wg.Wait()
ui := ui.New(c.Context)
events := bus.SubscribeAll()
defer close(events)
wg.Go(func() error {
for evt := range events {
ui.Event(evt)
}
return nil
})
s, err := server.New()
if err != nil {
return err
}
wg.Go(func() error {
defer c.Cancel()
return s.Start(c.Context, p)
})
defer ui.Destroy()
defer c.Cancel()
err = p.Run(c.Context, &project.StackInput{
Command: "refresh",
Target: target,
ServerPort: s.Port,
Verbose: c.Bool("verbose"),
})
if err != nil {
return err
}
return nil
}