-
Notifications
You must be signed in to change notification settings - Fork 7
/
init.go
96 lines (84 loc) · 1.98 KB
/
init.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
94
95
96
package commands
import (
"errors"
"fmt"
"path"
"strings"
"github.com/AlecAivazis/survey/v2"
"github.com/gobuffalo/here"
)
type initSurvey struct {
ModuleName string
ProjectName string
BinaryName string
AppName string
FriendlyAppName string
}
func runSurvey() (initSurvey, error) {
var results initSurvey
info, err := here.Current()
if err != nil {
return results, fmt.Errorf("could not get module information: %w", err)
}
if !info.Module.Main {
return results, errors.New("this project does not seem to be a Go application")
}
err = survey.AskOne(
&survey.Input{Message: "Go module name?", Default: info.Module.Path},
&results.ModuleName,
survey.WithValidator(survey.Required),
)
if err != nil {
return results, err
}
err = survey.AskOne(
&survey.Input{
Message: "Project name?",
Default: path.Base(results.ModuleName),
Help: "A directory-like name for your project (used in configurations, etc)",
},
&results.ProjectName,
survey.WithValidator(survey.Required),
)
if err != nil {
return results, err
}
err = survey.AskOne(
&survey.Input{
Message: "Binary name?",
Default: results.ProjectName,
Help: "Name of the main binary",
},
&results.BinaryName,
survey.WithValidator(survey.Required),
)
if err != nil {
return results, err
}
err = survey.AskOne(
&survey.Input{
Message: "Application name?",
Default: results.BinaryName,
Help: "Application name (if it differs from the binary name)",
},
&results.AppName,
survey.WithValidator(survey.Required),
)
if err != nil {
return results, err
}
var friendlyAppName string
err = survey.AskOne(
&survey.Input{
Message: "Friendly application name?",
Default: strings.Title(strings.ReplaceAll(results.AppName, "-", " ")), // nolint
Help: "User friendly application name (appearing eg. in logs)",
},
&friendlyAppName,
survey.WithValidator(survey.Required),
)
if err != nil {
return results, err
}
return results, nil
}