|
1 | 1 | package boilerplate
|
2 | 2 |
|
3 |
| -import "fmt" |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "prompt" |
| 7 | + |
| 8 | + packr "github.com/gobuffalo/packr/v2" |
| 9 | + color "github.com/logrusorgru/aurora" |
| 10 | +) |
| 11 | + |
| 12 | +func checkErr(err error) { |
| 13 | + if err != nil { |
| 14 | + fmt.Print(color.Red(err)) |
| 15 | + os.Exit(0) |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +var flows = map[string][]byte{ |
| 20 | + "default": []byte(""), |
| 21 | + "jira": []byte(""), |
| 22 | + "custom": []byte(""), |
| 23 | +} |
| 24 | + |
| 25 | +var flowTypes = []prompt.SelectItem{ |
| 26 | + {Title: "Default", Description: "Flow with module affected and message", Value: "default"}, |
| 27 | + {Title: "Jira", Description: "Flow based on Jira task", Value: "jira"}, |
| 28 | + {Title: "Custom", Description: "Flow with your own rules", Value: "custom"}, |
| 29 | +} |
| 30 | + |
| 31 | +var configurationSelectFlow = &prompt.SelectConfiguration{ |
| 32 | + ActiveTpl: "\U0001F449 {{ .Title | cyan }}", |
| 33 | + InactiveTpl: " {{ .Title | white }}", |
| 34 | + SelectPrompt: "Flow Type", |
| 35 | + SelectedTpl: "{{ \"Flow:\" | bold }} {{ .Title | green | bold }}", |
| 36 | + DetailsTpl: `------------------------------- |
| 37 | +{{ .Title | white | bold }} {{ .Description | white | bold }}`, |
| 38 | +} |
| 39 | + |
| 40 | +func createConfigurationFile(flowType string) error { |
| 41 | + projectFolder, err := os.Getwd() |
| 42 | + if err != nil { |
| 43 | + return err |
| 44 | + } |
| 45 | + |
| 46 | + configFile, err := os.Create(projectFolder + "/.cmf.yaml") |
| 47 | + defer configFile.Close() |
| 48 | + |
| 49 | + if err != nil { |
| 50 | + return err |
| 51 | + } |
| 52 | + |
| 53 | + _, err = configFile.Write(flows[flowType]) |
| 54 | + |
| 55 | + return err |
| 56 | +} |
4 | 57 |
|
5 | 58 | // Create a configuration file
|
6 | 59 | func Create() {
|
7 |
| - fmt.Println("CREATING FILE...") |
| 60 | + selector := |
| 61 | + prompt.Select(flowTypes, *configurationSelectFlow) |
| 62 | + |
| 63 | + err := createConfigurationFile(selector.Value) |
| 64 | + checkErr(err) |
| 65 | + |
| 66 | + fmt.Println(color.Gray("File .cmf.yaml for " + selector.Value + " flow generated ")) |
| 67 | + fmt.Println("Happy coding. \U0001F604") |
| 68 | +} |
| 69 | + |
| 70 | +func init() { |
| 71 | + box := packr.New("config", "../../configs") |
| 72 | + flows["default"], _ = box.Find("default.yaml") |
| 73 | + flows["jira"], _ = box.Find("jira.yaml") |
| 74 | + flows["custom"], _ = box.Find("custom.yaml") |
8 | 75 | }
|
0 commit comments