diff --git a/.gitignore b/.gitignore index ef5c25d..ab4726a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # editor specifics .idea .vscode +*.swp # Binaries for programs and plugins *.exe @@ -17,6 +18,7 @@ # build build/* +corgi # vendor vendor/* diff --git a/snippet/snippet.go b/snippet/snippet.go index 581d0fa..85aa286 100644 --- a/snippet/snippet.go +++ b/snippet/snippet.go @@ -140,17 +140,20 @@ func (snippet *Snippet) Export(outputPath string, fileType string) error { } func (snippet *Snippet) ConvertToShellScript() string { + green := color.New(color.FgGreen).SprintFunc() + yellow := color.New(color.FgYellow).SprintFunc() + templateFieldMap := snippet.BuildTemplateFieldMap() shellCmds := []string{} // headline shellCmds = append(shellCmds, "#!/bin/bash") // convert title - titleShell := fmt.Sprintf("echo -e \"%sStart executing snippet %s...%s\"\n", util.SHELL_GREEN, snippet.Title, util.SHELL_NO_COLOR) + titleShell := fmt.Sprintf("echo -e \"%s\"\n", green(fmt.Sprintf("Start executing snippet %s...", snippet.Title))) shellCmds = append(shellCmds, titleShell) // convert each step for idx, step := range snippet.Steps { stepCount := idx + 1 - stepIndexShell := fmt.Sprintf("echo -e \"\n%sStep %d:%s %s%s\"", util.SHELL_GREEN, stepCount, util.SHELL_YELLOW, step.Description, util.SHELL_NO_COLOR) + stepIndexShell := fmt.Sprintf("echo -e \"\nStep %d: %s\"", green(stepCount), yellow(step.Description)) stepShell := step.ConvertToShellScript(&templateFieldMap) shellCmds = append(shellCmds, stepIndexShell, stepShell, "\n") } diff --git a/snippet/step.go b/snippet/step.go index bd9541d..48751f9 100644 --- a/snippet/step.go +++ b/snippet/step.go @@ -47,6 +47,9 @@ func (step *StepInfo) AskQuestion(options ...interface{}) error { } func (step *StepInfo) ConvertToShellScript(templates *TemplateFieldMap) string { + green := color.New(color.FgGreen).SprintFunc() + yellow := color.New(color.FgYellow).SprintFunc() + shellCmds := make([]string, 0) templateFieldsMap := ParseTemplateFieldsMap(step.Command) for field := range templateFieldsMap { @@ -59,7 +62,7 @@ func (step *StepInfo) ConvertToShellScript(templates *TemplateFieldMap) string { defaultValPrompt = existingTf.Value defaultValueShell = fmt.Sprintf("%s=${%s:-%s}", field, field, existingTf.Value) } - inputPromptShell := fmt.Sprintf("read -p \"%sEnter value for <%s> (default: %s): %s\" %s", util.SHELL_GREEN, field, defaultValPrompt, util.SHELL_NO_COLOR, field) + inputPromptShell := fmt.Sprintf("read -p \"%s\" %s", green(fmt.Sprintf("Enter value for <%s> (default: %s):", field, defaultValPrompt)), field) existingTf.Asked = true shellCmds = append(shellCmds, inputPromptShell, defaultValueShell) } @@ -70,7 +73,7 @@ func (step *StepInfo) ConvertToShellScript(templates *TemplateFieldMap) string { field, _ := getParamNameAndValue(sub) return fmt.Sprintf("$%s", field) }) - runningPromptShell := fmt.Sprintf("echo -e \"%sRunning: %s%s%s\"", util.SHELL_GREEN, util.SHELL_YELLOW, executeShell, util.SHELL_NO_COLOR) + runningPromptShell := fmt.Sprintf(`echo -e "%s %s"`, green("Running:"), yellow(executeShell)) shellCmds = append(shellCmds, runningPromptShell, executeShell) return strings.Join(shellCmds, "\n") } diff --git a/util/util.go b/util/util.go index ff34ffe..7987418 100644 --- a/util/util.go +++ b/util/util.go @@ -20,13 +20,6 @@ const ( NEXT_LINE_SUFFIX = "\\" ) -const ( - SHELL_RED = "\033[0;31m" - SHELL_GREEN = "\033[0;32m" - SHELL_YELLOW = "\033[1;33m" - SHELL_NO_COLOR = "\033[0m" -) - func LoadJsonDataFromFile(filePath string, object interface{}) error { data, err := ioutil.ReadFile(filePath) if err != nil {