Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/gpctl/cmd/workspaces-subscribe.go
2498 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"context"
9
"fmt"
10
11
"github.com/spf13/cobra"
12
13
"github.com/gitpod-io/gitpod/common-go/log"
14
"github.com/gitpod-io/gitpod/ws-manager/api"
15
)
16
17
// workspacesSubscribeCmd represents the describe command
18
var workspacesSubscribeCmd = &cobra.Command{
19
Use: "subscribe",
20
Short: "subscribes to all workspace status updates",
21
Run: func(cmd *cobra.Command, args []string) {
22
ctx, cancel := context.WithCancel(context.Background())
23
defer cancel()
24
25
conn, client, err := getWorkspacesClient(ctx)
26
if err != nil {
27
log.WithError(err).Fatal("cannot connect")
28
}
29
defer conn.Close()
30
31
sub, err := client.Subscribe(ctx, &api.SubscribeRequest{})
32
if err != nil {
33
log.WithError(err).Fatal("error during RPC call")
34
}
35
defer sub.CloseSend()
36
37
tpl := `{{ .Metadata.MetaId }} {{ .Id }} {{ .Phase -}}`
38
for {
39
resp, err := sub.Recv()
40
if err != nil {
41
log.WithError(err).Error()
42
return
43
}
44
45
err = getOutputFormat(tpl, "{..id}").Print(resp.Status)
46
if err != nil {
47
log.WithError(err).Error()
48
return
49
}
50
fmt.Println()
51
}
52
},
53
}
54
55
func init() {
56
workspacesCmd.AddCommand(workspacesSubscribeCmd)
57
}
58
59