Commit 0b975b92 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

command/inspect: show required variables differently

parent 2752db25
......@@ -44,10 +44,20 @@ func (c Command) Run(env packer.Environment, args []string) int {
ui := env.Ui()
// Variables
ui.Say("Variables and their defaults:\n")
if len(tpl.Variables) == 0 {
ui.Say("Variables:\n")
ui.Say(" <No variables>")
} else {
ui.Say("Required variables:\n")
for k, v := range tpl.Variables {
if v.Required {
ui.Machine("template-variable", k, v.Default, "1")
ui.Say(" " + k)
}
}
ui.Say("")
ui.Say("Optional variables and their defaults:\n")
keys := make([]string, 0, len(tpl.Variables))
max := 0
for k, _ := range tpl.Variables {
......@@ -61,10 +71,14 @@ func (c Command) Run(env packer.Environment, args []string) int {
for _, k := range keys {
v := tpl.Variables[k]
if v.Required {
continue
}
padding := strings.Repeat(" ", max-len(k))
output := fmt.Sprintf(" %s%s = %s", k, padding, v)
ui.Machine("template-variable", k, v)
ui.Machine("template-variable", k, v.Default, "0")
ui.Say(output)
}
}
......
......@@ -9,7 +9,7 @@ These are the machine-readable types that exist as part of the output
of `packer inspect`.
<dl>
<dt>template-variable (2)</dt>
<dt>template-variable (3)</dt>
<dd>
<p>
A <a href="/docs/templates/user-variables.html">user variable</a>
......@@ -24,6 +24,11 @@ of `packer inspect`.
<strong>Data 2: default</strong> - The default value of the
variable.
</p>
<p>
<strong>Data 3: required</strong> - If non-zero, then this variable
is required.
</p>
</dd>
<dt>template-builder (2)</dt>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment