-
Notifications
You must be signed in to change notification settings - Fork 7
/
prompts.go
87 lines (74 loc) · 1.73 KB
/
prompts.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
package create
import (
"path/filepath"
"strings"
"github.com/manifoldco/promptui"
"github.com/natewong1313/go-react-ssr/cli/logger"
"github.com/natewong1313/go-react-ssr/cli/utils"
)
func prompt_getProjectDirectory(args []string) string {
display := func(path string) string {
logger.L.Info().Msg("Creating project at " + path)
return path
}
if len(args) > 0 {
projectDir, err := filepath.Abs(args[0])
if err != nil {
utils.HandleError(err)
}
return display(projectDir)
}
prompt := promptui.Prompt{
Label: "Enter the path of your project (leave blank to use current directory)",
}
result, err := prompt.Run()
projectDir, err := filepath.Abs(result)
if err != nil {
utils.HandleError(err)
}
return display(projectDir)
}
func prompt_selectWebFramework() string {
prompt := promptui.Select{
Label: "Select a web framework to use",
Items: []string{"Gin", "Fiber"},
}
_, result, err := prompt.Run()
if err != nil {
utils.HandleError(err)
}
return result
}
func prompt_isUsingTailwind() bool {
prompt := promptui.Prompt{
Label: "Use Tailwind? (y/n)",
Default: "n",
}
result, err := prompt.Run()
if err != nil {
utils.HandleError(err)
}
return strings.ToLower(result) == "y"
}
func prompt_isUsingTypescript() bool {
prompt := promptui.Prompt{
Label: "Use Typescript? (y/n)",
Default: "y",
}
result, err := prompt.Run()
if err != nil {
utils.HandleError(err)
}
return strings.ToLower(result) == "y"
}
func prompt_shouldWipeDirectory() bool {
prompt := promptui.Prompt{
Label: "Directory is not empty. Continue? (this will wipe the directory) (y/n)",
Default: "n",
}
result, err := prompt.Run()
if err != nil {
utils.HandleError(err)
}
return strings.ToLower(result) == "y"
}