-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.go
93 lines (71 loc) · 1.76 KB
/
edit.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package features
import (
"github.com/yolo-sh/agent/constants"
"github.com/yolo-sh/cli/internal/interfaces"
"github.com/yolo-sh/yolo/features"
)
type EditResponse struct {
Error error
Content EditResponseContent
}
type EditResponseContent struct {
EnvName string
}
type EditPresenter interface {
PresentToView(EditResponse)
}
type EditOutputHandler struct {
presenter EditPresenter
vscodeProcess interfaces.VSCodeProcessManager
vscodeExtensions interfaces.VSCodeExtensionsManager
}
func NewEditOutputHandler(
presenter EditPresenter,
vscodeProcess interfaces.VSCodeProcessManager,
vscodeExtensions interfaces.VSCodeExtensionsManager,
) EditOutputHandler {
return EditOutputHandler{
presenter: presenter,
vscodeProcess: vscodeProcess,
vscodeExtensions: vscodeExtensions,
}
}
func (e EditOutputHandler) HandleOutput(output features.EditOutput) error {
stepper := output.Stepper
handleError := func(err error) error {
stepper.StopCurrentStep()
e.presenter.PresentToView(EditResponse{
Error: err,
})
return err
}
if output.Error != nil {
return handleError(output.Error)
}
stepper.StartTemporaryStepWithoutNewLine(
"Installing Visual Studio Code Remote - SSH extension",
)
_, err := e.vscodeExtensions.Install("ms-vscode-remote.remote-ssh")
if err != nil {
return handleError(err)
}
stepper.StartTemporaryStepWithoutNewLine(
"Opening Visual Studio Code",
)
env := output.Content.Env
sshConfigHostKey := env.Name
_, err = e.vscodeProcess.OpenOnRemote(
sshConfigHostKey,
constants.VSCodeWorkspaceConfigFilePath,
)
if err != nil {
return handleError(err)
}
stepper.StopCurrentStep()
e.presenter.PresentToView(EditResponse{
Content: EditResponseContent{
EnvName: env.Name,
},
})
return nil
}