-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailhog.go
76 lines (59 loc) · 1.53 KB
/
mailhog.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 services
import (
"fmt"
"os"
"strconv"
"github.com/AlecAivazis/survey/v2"
)
type MailHogService struct{}
func (s *MailHogService) GetName() string {
return "MailHog"
}
func (s *MailHogService) GetDefaultPort() int {
return 1025
}
func (s *MailHogService) GetOrganization() string {
return "mailhog"
}
func (s *MailHogService) GetImageName() string {
return "mailhog"
}
func (s *MailHogService) GetDefaults() map[string]string {
values := map[string]string{
"port": strconv.Itoa(s.GetDefaultPort()),
"web_port": "8025",
}
// merge base defaults with service defaults
for key, value := range DefaultOptions() {
values[key] = value
}
return values
}
func (s *MailHogService) Prompt() (map[string]string, error) {
defaults := s.GetDefaults()
prompts := []*survey.Question{
{
Name: "web_port",
Prompt: &survey.Input{Message: "What will the web port be?", Default: defaults["web_port"]},
Validate: survey.Required,
},
}
prompts = append(DefaultPrompts(s.GetDefaultPort()), prompts...)
var answers = make(map[string]interface{})
err := survey.Ask(prompts, &answers)
if err != nil {
os.Exit(1)
}
var mapped = make(map[string]string)
// convert all answers into strings and add to mapped
for key, value := range answers {
mapped[key] = value.(string)
}
return mapped, nil
}
func (s *MailHogService) GetDockerCommandArgs(options map[string]string) []string {
return []string{
fmt.Sprintf("--publish=%s:1025", options["port"]),
fmt.Sprintf("--publish=%s:8025", options["port"]),
}
}