Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# editor specifics
.idea
.vscode
*.swp

# Binaries for programs and plugins
*.exe
Expand All @@ -17,6 +18,7 @@

# build
build/*
corgi

# vendor
vendor/*
Expand Down
7 changes: 5 additions & 2 deletions snippet/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
7 changes: 5 additions & 2 deletions snippet/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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")
}
Expand Down
7 changes: 0 additions & 7 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down