forked from joselitofilho/aws-terraform-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structure.go
59 lines (45 loc) · 1.29 KB
/
structure.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
package guides
import (
"fmt"
"strings"
"github.com/AlecAivazis/survey/v2"
surveyasker "github.com/joselitofilho/aws-terraform-generator/internal/survey"
)
type StructureAnswers struct {
Config string
Output string
}
func GuideStructure(
surveyAsker surveyasker.Asker, workdir string, fileMap map[string][]string,
) (*StructureAnswers, error) {
if len(fileMap["config"]) == 0 {
return nil, ErrDirDoesNotContainAnyConfigFile
}
configOptions := make([]string, 0, len(fileMap["config"]))
configOptions = append(configOptions, fileMap["config"]...)
answers := StructureAnswers{}
var defaultConfigOption int
for i := range configOptions {
if strings.Contains(configOptions[i], "structure.config") {
defaultConfigOption = i
}
}
if err := surveyAsker.AskOne(&survey.Select{
Message: "Choose a config:",
Default: defaultConfigOption,
Options: configOptions,
}, &answers.Config); err != nil {
return nil, fmt.Errorf("%w", err)
}
answers.Config = replaceDoubleSlash(fmt.Sprintf("%s/%s", workdir, answers.Config))
if err := surveyAsker.AskOne(
&survey.Input{
Message: "Enter the output folder:",
Default: "./output",
},
&answers.Output); err != nil {
return nil, fmt.Errorf("%w", err)
}
answers.Output = replaceDoubleSlash(answers.Output)
return &answers, nil
}