-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ibuildthecloud/changes
Changes
- Loading branch information
Showing
336 changed files
with
5,605 additions
and
881 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/mitchellh/mapstructure" | ||
"github.com/rancher/go-rancher/catalog" | ||
) | ||
|
||
func askQuestions(answers map[string]interface{}, templateVersion catalog.TemplateVersion) (map[string]interface{}, error) { | ||
result := map[string]interface{}{} | ||
for _, q := range templateVersion.Questions { | ||
question := catalog.Question{} | ||
err := mapstructure.Decode(q, &question) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if answer, ok := answers[question.Variable]; ok { | ||
result[question.Variable] = answer | ||
} else { | ||
result[question.Variable] = askQuestion(question) | ||
} | ||
} | ||
return result, nil | ||
} | ||
|
||
func askQuestion(question catalog.Question) interface{} { | ||
if len(question.Description) > 0 { | ||
fmt.Println(question.Description) | ||
} | ||
fmt.Printf("%s %s[%s]: ", question.Label, question.Variable, question.Default) | ||
|
||
answer, err := bufio.NewReader(os.Stdin).ReadString('\n') | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
answer = strings.TrimSpace(answer) | ||
if answer == "" { | ||
answer = question.Default | ||
} | ||
|
||
return answer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.