-
Notifications
You must be signed in to change notification settings - Fork 290
/
demo.go
55 lines (44 loc) · 1.06 KB
/
demo.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
package cli
import (
"context"
"errors"
"time"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/windmilleng/tilt/internal/analytics"
"github.com/windmilleng/tilt/internal/demo"
)
type demoCmd struct {
branch string
}
func (c *demoCmd) register() *cobra.Command {
cmd := &cobra.Command{
Use: "demo",
Short: "Run the demo script",
}
cmd.Flags().StringVar(&c.branch, "branch", "",
"Checks out a branch of the tiltdemo repo, instead of the master branch")
return cmd
}
func (c *demoCmd) run(ctx context.Context, args []string) error {
a := analytics.Get(ctx)
a.Incr("cmd.demo", map[string]string{})
defer a.Flush(time.Second)
demo, err := wireDemo(ctx, demo.RepoBranch(c.branch), a)
if err != nil {
return err
}
err = demo.Run(ctx)
s, ok := status.FromError(err)
if ok && s.Code() == codes.Unknown {
return errors.New(s.Message())
} else if err != nil {
if err == context.Canceled {
// Expected case, no need to be loud about it, just exit
return nil
}
return err
}
return nil
}