-
Notifications
You must be signed in to change notification settings - Fork 7
/
start.go
76 lines (57 loc) · 1.73 KB
/
start.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
package presenters
import (
"github.com/recode-sh/cli/internal/constants"
"github.com/recode-sh/cli/internal/features"
)
type StartViewData struct {
Error *ViewableError
Content StartViewDataContent
}
type StartViewDataContent struct {
ShowAsWarning bool
Message string
Subtext string
}
type StartViewer interface {
View(StartViewData)
}
type StartPresenter struct {
viewableErrorBuilder ViewableErrorBuilder
viewer StartViewer
}
func NewStartPresenter(
viewableErrorBuilder ViewableErrorBuilder,
viewer StartViewer,
) StartPresenter {
return StartPresenter{
viewableErrorBuilder: viewableErrorBuilder,
viewer: viewer,
}
}
func (s StartPresenter) PresentToView(response features.StartResponse) {
viewData := StartViewData{}
if response.Error == nil {
devEnvName := response.Content.DevEnvName
viewDataMessage := "The development environment \"" + devEnvName + "\" was started."
viewDataSubtext := "Run `" + constants.Blue("ssh "+devEnvName) + "` (or use your code editor's integrated terminal)."
devEnvAlreadyStarted := response.Content.DevEnvAlreadyStarted
if devEnvAlreadyStarted {
viewDataMessage = "The development environment \"" + devEnvName + "\" is already started."
viewDataSubtext = ""
}
devEnvRebuilt := response.Content.DevEnvRebuilt
if devEnvRebuilt {
viewDataMessage = "The development environment \"" + devEnvName + "\" was rebuilt."
viewDataSubtext = ""
}
viewData.Content = StartViewDataContent{
ShowAsWarning: devEnvAlreadyStarted,
Message: viewDataMessage,
Subtext: viewDataSubtext,
}
s.viewer.View(viewData)
return
}
viewData.Error = s.viewableErrorBuilder.Build(response.Error)
s.viewer.View(viewData)
}