-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ask.go
78 lines (61 loc) · 1.75 KB
/
ask.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
package internal
import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"golang.org/x/exp/maps"
)
func askLanguage(fileNames []string, selected []string, files map[string]string) ([]string, []string) {
fmt.Println()
langSelections := askMulti("Please select which you want to write to .gitignore:\n", maps.Keys(files))
keys := []string{}
for _, selection := range langSelections {
selected = append(selected, files[selection])
keys = append(keys, selection)
}
return selected, keys
}
func askDiscovery() bool {
return askYesNo("Would you like to try to scan for available templates automatically?\n"+
"Select 'No' to see all available templates", true)
}
func AskOverwrite() string {
fmt.Println()
return askSelection(
".gitignore file found in this directory. Please pick an option:",
[]string{"Overwrite", "Append", "Skip"},
"Overwrite",
)
}
func AskCleanup() bool {
fmt.Println()
return askYesNo("Do you want to remove patterns not existing in your project?\n"+
"This might produce incomplete files on new projects.", false)
}
func askYesNo(message string, defaultValue bool) bool {
return askSelection(message, []string{"Yes", "No"}, Ternary(defaultValue, "Yes", "No")) == "Yes"
}
func askMulti(message string, options []string) []string {
langPrompt := &survey.MultiSelect{
Message: message,
Options: options,
}
var selections []string
survey.AskOne(langPrompt, &selections)
if selections == nil {
KeyInterrupt()
}
return selections
}
func askSelection(message string, options []string, defaultValue string) string {
langPrompt := &survey.Select{
Message: message,
Options: options,
Default: defaultValue,
}
selection := ""
survey.AskOne(langPrompt, &selection)
if selection == "" {
KeyInterrupt()
}
return selection
}