command/inspect: cleaner output if no required vars

This commit is contained in:
Mitchell Hashimoto 2013-08-31 17:49:22 -07:00
parent 0b975b9203
commit 977969a7e9
1 changed files with 10 additions and 2 deletions

View File

@ -48,15 +48,23 @@ func (c Command) Run(env packer.Environment, args []string) int {
ui.Say("Variables:\n")
ui.Say(" <No variables>")
} else {
ui.Say("Required variables:\n")
requiredHeader := false
for k, v := range tpl.Variables {
if v.Required {
if !requiredHeader {
requiredHeader = true
ui.Say("Required variables:\n")
}
ui.Machine("template-variable", k, v.Default, "1")
ui.Say(" " + k)
}
}
ui.Say("")
if requiredHeader {
ui.Say("")
}
ui.Say("Optional variables and their defaults:\n")
keys := make([]string, 0, len(tpl.Variables))
max := 0