Skip to content

Commit

Permalink
Merge pull request #15 from Ilyes512/0.4.4
Browse files Browse the repository at this point in the history
0.4.4
  • Loading branch information
Ilyes512 authored Aug 16, 2018
2 parents 34ef598 + 07bf1d3 commit 429d57d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 25 deletions.
106 changes: 88 additions & 18 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
)

func (p boolPrompt) EvaluateChoice(c string) (interface{}, error) {
if val, ok := booleanValues[c]; ok {
if val, ok := booleanValues[strings.ToLower(c)]; ok {
return val, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func handleBindPrompts(t *dirTemplate, parentKey string) {

return val
}
}(t.Context[parentKey], childPrompt)
}(childMap[childKey], childPrompt)
}
} else {
t.FuncMap[parentKey] = prompt.New(parentKey, t.Context[parentKey])
Expand Down
19 changes: 14 additions & 5 deletions pkg/util/tlog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,33 @@ func Fatal(msg string) {

// Prompt outputs the given message as a question along with a default value.
func Prompt(msg string, defval interface{}) {
whiteBold := color.New(color.Bold, color.FgWhite).SprintFunc()
blueBold := color.New(color.Bold, color.FgBlue).SprintFunc()

tokens := []string{
color.New(color.FgBlue).SprintFunc()("[" + QuestionMark + "]"),
color.New(color.Bold, color.FgWhite).SprintFunc()(msg),
whiteBold(msg),
}

// TODO refactor & eliminate duplication
switch val := defval.(type) {
case []interface{}:
tokens = append(tokens, "\n")
for i, v := range val {
tokens = append(tokens, color.New(color.Bold, color.FgWhite).SprintFunc()(fmt.Sprintf(" %v - %#v\n", i+1, v)))
tokens = append(tokens, whiteBold(fmt.Sprintf(" %v - %#v\n", i+1, v)))
}

tokens = append(tokens, color.New(color.Bold, color.FgWhite).SprintFunc()(fmt.Sprintf(" Choose from %v..%v", 1, len(val))))
tokens = append(tokens, whiteBold(fmt.Sprintf(" Choose from %v..%v", 1, len(val))))
tokens = append(tokens, blueBold(fmt.Sprintf("[default: %v]: ", 1)))
case bool:
boolText := "no"
if defval == true {
boolText = "yes"
}

tokens = append(tokens, color.New(color.Bold, color.FgBlue).SprintFunc()(fmt.Sprintf("[default: %v]: ", 1)))
tokens = append(tokens, blueBold(fmt.Sprintf("[default: %s]: ", boolText)))
default:
tokens = append(tokens, color.New(color.Bold, color.FgBlue).SprintFunc()(fmt.Sprintf("[default: %#v]: ", defval)))
tokens = append(tokens, blueBold(fmt.Sprintf("[default: %#v]: ", defval)))
}

fmt.Print(strings.Join(tokens, " "))
Expand Down

0 comments on commit 429d57d

Please sign in to comment.