add docs and the option to list variables from inside the console

This commit is contained in:
Megan Marsh
2019-06-06 14:26:12 -07:00
parent df916e805e
commit 668e92f2ca
2 changed files with 114 additions and 0 deletions
+11
View File
@@ -191,6 +191,8 @@ func (s *REPLSession) Handle(line string) (string, error) {
return "", ErrSessionExit
case strings.TrimSpace(line) == "help":
return s.handleHelp()
case strings.TrimSpace(line) == "variables":
return s.handleVariables()
default:
return s.handleEval(line)
}
@@ -205,6 +207,15 @@ func (s *REPLSession) handleEval(line string) (string, error) {
return rendered, nil
}
func (s *REPLSession) handleVariables() (string, error) {
varsstring := "\n"
for k, v := range s.Core.Context().UserVariables {
varsstring += fmt.Sprintf("%s: %+v,\n", k, v)
}
return varsstring, nil
}
func (s *REPLSession) handleHelp() (string, error) {
text := `
The Packer console allows you to experiment with Packer interpolations.