Skip to content

Commit 11c412b

Browse files
akosyakovroboquat
authored andcommitted
[gp-cli] remove unused code
1 parent f668ab4 commit 11c412b

File tree

6 files changed

+44
-563
lines changed

6 files changed

+44
-563
lines changed

components/gitpod-cli/cmd/open.go

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
package cmd
66

77
import (
8+
"context"
89
"log"
910
"os"
1011
"os/exec"
11-
"sync"
12-
"time"
12+
13+
supervisorClient "github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor-helper"
1314

1415
"github.com/google/shlex"
1516
"github.com/spf13/cobra"
1617
"golang.org/x/sys/unix"
17-
18-
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/theialib"
1918
)
2019

2120
// initCmd represents the init command
@@ -24,14 +23,16 @@ var openCmd = &cobra.Command{
2423
Short: "Opens a file in Gitpod",
2524
Args: cobra.MinimumNArgs(1),
2625
Run: func(cmd *cobra.Command, args []string) {
27-
wait, _ := cmd.Flags().GetBool("wait")
26+
// TODO(ak) use NotificationService.NotifyActive supervisor API instead
2827

29-
err := tryOpenInTheia(args, wait)
30-
if err == nil {
31-
// opening in Theia worked - we're good
32-
return
28+
ctx := context.Background()
29+
err := supervisorClient.WaitForIDEReady(ctx)
30+
if err != nil {
31+
log.Fatal(err)
3332
}
3433

34+
wait, _ := cmd.Flags().GetBool("wait")
35+
3536
pcmd := os.Getenv("GP_OPEN_EDITOR")
3637
if pcmd == "" {
3738
log.Fatal("GP_OPEN_EDITOR is not set")
@@ -65,46 +66,3 @@ func init() {
6566
rootCmd.AddCommand(openCmd)
6667
openCmd.Flags().BoolP("wait", "w", false, "wait until all opened files are closed again")
6768
}
68-
69-
func tryOpenInTheia(args []string, wait bool) error {
70-
service, err := theialib.NewServiceFromEnv()
71-
if err != nil {
72-
return err
73-
}
74-
75-
var wg sync.WaitGroup
76-
for _, fn := range args {
77-
if fn == "--wait" {
78-
continue
79-
}
80-
81-
_, err := service.OpenFile(theialib.OpenFileRequest{Path: fn})
82-
if err != nil {
83-
return err
84-
}
85-
if !wait {
86-
continue
87-
}
88-
89-
wg.Add(1)
90-
go func(fn string) {
91-
defer wg.Done()
92-
93-
for {
94-
resp, err := service.IsFileOpen(theialib.IsFileOpenRequest{Path: fn})
95-
if err != nil {
96-
log.Fatal(err)
97-
return
98-
}
99-
if !resp.IsOpen {
100-
return
101-
}
102-
103-
time.Sleep(1 * time.Second)
104-
}
105-
}(fn)
106-
}
107-
108-
wg.Wait()
109-
return nil
110-
}

components/gitpod-cli/cmd/preview.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
package cmd
66

77
import (
8+
"context"
89
"log"
910
"os"
1011
"os/exec"
1112
"regexp"
1213
"strconv"
1314
"strings"
1415

16+
supervisorClient "github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor-helper"
1517
"github.com/google/shlex"
1618
"github.com/spf13/cobra"
1719
"golang.org/x/sys/unix"
@@ -29,6 +31,13 @@ var previewCmd = &cobra.Command{
2931
Short: "Opens a URL in the IDE's preview",
3032
Args: cobra.ExactArgs(1),
3133
Run: func(cmd *cobra.Command, args []string) {
34+
// TODO(ak) use NotificationService.NotifyActive supervisor API instead
35+
36+
ctx := context.Background()
37+
err := supervisorClient.WaitForIDEReady(ctx)
38+
if err != nil {
39+
log.Fatal(err)
40+
}
3241
url := replaceLocalhostInURL(args[0])
3342
if previewCmdOpts.External {
3443
if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {

components/gitpod-cli/pkg/supervisor-helper/supervisor.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,43 @@ package supervisor_helper
66

77
import (
88
"context"
9+
"time"
910

1011
"golang.org/x/xerrors"
1112
"google.golang.org/grpc"
1213
"google.golang.org/grpc/credentials/insecure"
1314

1415
"github.com/gitpod-io/gitpod/common-go/util"
16+
supervisor "github.com/gitpod-io/gitpod/supervisor/api"
1517
)
1618

19+
// TODO(ak) introduce proper abstraction, like SupervisorClient
20+
1721
func Dial(ctx context.Context) (*grpc.ClientConn, error) {
1822
supervisorConn, err := grpc.DialContext(ctx, util.GetSupervisorAddress(), grpc.WithTransportCredentials(insecure.NewCredentials()))
1923
if err != nil {
2024
err = xerrors.Errorf("failed connecting to supervisor: %w", err)
2125
}
2226
return supervisorConn, err
2327
}
28+
29+
func WaitForIDEReady(ctx context.Context) error {
30+
conn, err := Dial(ctx)
31+
if err != nil {
32+
return err
33+
}
34+
defer conn.Close()
35+
client := supervisor.NewStatusServiceClient(conn)
36+
37+
var ideReady bool
38+
for !ideReady {
39+
resp, _ := client.IDEStatus(ctx, &supervisor.IDEStatusRequest{Wait: true})
40+
if resp != nil {
41+
ideReady = resp.Ok
42+
}
43+
if !ideReady {
44+
time.Sleep(1 * time.Second)
45+
}
46+
}
47+
return nil
48+
}

components/gitpod-cli/pkg/theialib/mock.go

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)