Skip to content

Commit 4c064d1

Browse files
committed
open on setup script done
1 parent d26b41c commit 4c064d1

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

pkg/cmd/envsetup/envsetup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (e envInitier) Setup() error { //nolint:funlen,gocyclo // TODO
296296
if err != nil {
297297
return breverrors.WrapAndTrace(err)
298298
}
299-
299+
fmt.Println("------ Done running execs ------")
300300
err = appendLogToFile("done running execs", "/var/log/brev-steps.log")
301301
if err != nil {
302302
return breverrors.WrapAndTrace(err)

pkg/cmd/open/open.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ func NewCmdOpen(t *terminal.Terminal, store OpenStore, noLoginStartStore OpenSto
5959
Args: cmderrors.TransformToValidationError(cobra.ExactArgs(1)),
6060
ValidArgsFunction: completions.GetAllWorkspaceNameCompletionHandler(noLoginStartStore, t),
6161
RunE: func(cmd *cobra.Command, args []string) error {
62-
err := runOpenCommand(t, store, args[0], waitForSetupToFinish)
62+
setupDoneString := "------ Git repo cloned ------"
63+
if waitForSetupToFinish {
64+
setupDoneString = "------ Done running execs ------"
65+
}
66+
err := runOpenCommand(t, store, args[0], setupDoneString)
6367
if err != nil {
6468
return breverrors.WrapAndTrace(err)
6569
}
@@ -72,7 +76,7 @@ func NewCmdOpen(t *terminal.Terminal, store OpenStore, noLoginStartStore OpenSto
7276
}
7377

7478
// Fetch workspace info, then open code editor
75-
func runOpenCommand(t *terminal.Terminal, tstore OpenStore, wsIDOrName string, waitForSetupToFinish bool) error {
79+
func runOpenCommand(t *terminal.Terminal, tstore OpenStore, wsIDOrName string, setupDoneString string) error {
7680
// todo check if workspace is stopped and start if it if it is stopped
7781
fmt.Println("finding your dev environment...")
7882
res := refresh.RunRefreshAsync(tstore)
@@ -120,7 +124,7 @@ func runOpenCommand(t *terminal.Terminal, tstore OpenStore, wsIDOrName string, w
120124
// legacy environments wont support this and cause errrors,
121125
// but we don't want to block the user from using vscode
122126
_ = writeconnectionevent.WriteWCEOnEnv(tstore, string(localIdentifier))
123-
err = openVsCodeWithSSH(t, string(localIdentifier), projPath, tstore, waitForSetupToFinish)
127+
err = openVsCodeWithSSH(t, string(localIdentifier), projPath, tstore, setupDoneString)
124128
if err != nil {
125129
if strings.Contains(err.Error(), `"code": executable file not found in $PATH`) {
126130
errMsg := "code\": executable file not found in $PATH\n\nadd 'code' to your $PATH to open VS Code from the terminal\n\texport PATH=\"/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH\""
@@ -195,7 +199,7 @@ func openVsCodeWithSSH(
195199
sshAlias string,
196200
path string,
197201
tstore OpenStore,
198-
waitForSetupToFinish bool,
202+
setupDoneString string,
199203
) error {
200204
// infinite for loop:
201205
res := refresh.RunRefreshAsync(tstore)
@@ -215,12 +219,12 @@ func openVsCodeWithSSH(
215219
if err != nil {
216220
return breverrors.WrapAndTrace(err)
217221
}
218-
setupFinished, err := checkSetupFinished(sshAlias, waitForSetupToFinish)
222+
setupFinished, err := checkSetupFinished(sshAlias, setupDoneString)
219223
if err != nil {
220224
return breverrors.WrapAndTrace(err)
221225
}
222226
if !setupFinished {
223-
err = streamOutput(t, s, sshAlias, path, waitForSetupToFinish, tstore)
227+
err = streamOutput(t, s, sshAlias, path, setupDoneString, tstore)
224228
if err != nil {
225229
return breverrors.WrapAndTrace(err)
226230
}
@@ -299,20 +303,21 @@ func waitForLoggerFileToBeAvailable(t *terminal.Terminal, s *spinner.Spinner, ss
299303
}
300304
}
301305

302-
func checkSetupFinished(sshAlias string, waitForSetupToFinish bool) (bool, error) {
306+
func checkSetupFinished(sshAlias string, setupDoneString string) (bool, error) {
303307
out, err := exec.Command("ssh", "-o", "RemoteCommand=none", sshAlias, "cat", "/var/log/brev-workspace.log").CombinedOutput() // RemoteCommand=none
304308
if err != nil {
305309
return false, breverrors.WrapAndTrace(err)
306310
}
307-
return (strings.Contains(string(out), "------ Setup End ------") || (!waitForSetupToFinish && strings.Contains(string(out), "------ Git repo cloned ------"))), nil
311+
312+
return (strings.Contains(string(out), "------ Setup End ------") || strings.Contains(string(out), setupDoneString)), nil
308313
}
309314

310315
func streamOutput(
311316
t *terminal.Terminal,
312317
s *spinner.Spinner,
313318
sshAlias string,
314319
path string,
315-
waitForSetupToFinish bool,
320+
setupDoneString string,
316321
store OpenStore,
317322
) error {
318323
s.Suffix = t.Green(" should be no more than a minute now...hit ENTER to see logs")
@@ -334,7 +339,7 @@ func streamOutput(
334339
&vscodeAlreadyOpened,
335340
&showLogsToUser,
336341
errChannel,
337-
waitForSetupToFinish,
342+
setupDoneString,
338343
store,
339344
)
340345

@@ -364,14 +369,14 @@ func scanLoggerFile(
364369
vscodeAlreadyOpened *bool,
365370
showLogsToUser *bool,
366371
err chan error,
367-
waitForSetupToFinish bool,
372+
setupDoneString string,
368373
store OpenStore,
369374
) {
370375
for scanner.Scan() {
371376
if *showLogsToUser {
372377
fmt.Println("\n", scanner.Text())
373378
}
374-
if strings.Contains(scanner.Text(), "------ Setup End ------") || (!waitForSetupToFinish && strings.Contains(scanner.Text(), "------ Git repo cloned ------")) {
379+
if strings.Contains(scanner.Text(), "------ Setup End ------") || strings.Contains(scanner.Text(), setupDoneString) {
375380
if !*vscodeAlreadyOpened {
376381
s.Stop()
377382
err <- openVsCode(sshAlias, path, store)

0 commit comments

Comments
 (0)