Skip to content

Commit de7037f

Browse files
author
Dhia Ayachi
committed
validate the type
1 parent 6a25734 commit de7037f

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

cmd/changelog-gen/main.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,19 @@ func main() {
6363
os.Exit(1)
6464
}
6565
}
66-
66+
typeValues := []string{"enhancement",
67+
"feature",
68+
"bug",
69+
"note",
70+
"new-resource",
71+
"new-datasource",
72+
"deprecation",
73+
"breaking-change",
74+
}
6775
if Type == "" {
6876
prompt := promptui.Select{
6977
Label: "Select a change type",
70-
Items: []string{"enhancement",
71-
"bug",
72-
"note",
73-
"new-resource",
74-
"new-datasource",
75-
"deprecation",
76-
"breaking-change",
77-
"none"},
78+
Items: typeValues,
7879
}
7980

8081
_, Type, err = prompt.Run()
@@ -85,6 +86,13 @@ func main() {
8586
flag.Usage()
8687
os.Exit(1)
8788
}
89+
} else {
90+
if !TypeValid(typeValues, Type) {
91+
fmt.Fprintln(os.Stderr, "Must specify a valid type")
92+
fmt.Fprintln(os.Stderr, "")
93+
flag.Usage()
94+
os.Exit(1)
95+
}
8896
}
8997

9098
if Description == "" {
@@ -131,6 +139,15 @@ func main() {
131139
}
132140
}
133141

142+
func TypeValid(elements []string, Type string) bool {
143+
for _, a := range elements {
144+
if a == Type {
145+
return true
146+
}
147+
}
148+
return false
149+
}
150+
134151
func OpenGit(path string) (*git.Repository, error) {
135152
r, err := git.PlainOpen(path)
136153
if err != nil {

0 commit comments

Comments
 (0)