command/inspect: show required variables differently
This commit is contained in:
parent
2752db25c0
commit
0b975b9203
@ -44,10 +44,20 @@ func (c Command) Run(env packer.Environment, args []string) int {
|
|||||||
ui := env.Ui()
|
ui := env.Ui()
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
ui.Say("Variables and their defaults:\n")
|
|
||||||
if len(tpl.Variables) == 0 {
|
if len(tpl.Variables) == 0 {
|
||||||
|
ui.Say("Variables:\n")
|
||||||
ui.Say(" <No variables>")
|
ui.Say(" <No variables>")
|
||||||
} else {
|
} 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))
|
keys := make([]string, 0, len(tpl.Variables))
|
||||||
max := 0
|
max := 0
|
||||||
for k, _ := range tpl.Variables {
|
for k, _ := range tpl.Variables {
|
||||||
@ -61,10 +71,14 @@ func (c Command) Run(env packer.Environment, args []string) int {
|
|||||||
|
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
v := tpl.Variables[k]
|
v := tpl.Variables[k]
|
||||||
|
if v.Required {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
padding := strings.Repeat(" ", max-len(k))
|
padding := strings.Repeat(" ", max-len(k))
|
||||||
output := fmt.Sprintf(" %s%s = %s", k, padding, v)
|
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)
|
ui.Say(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ These are the machine-readable types that exist as part of the output
|
|||||||
of `packer inspect`.
|
of `packer inspect`.
|
||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
<dt>template-variable (2)</dt>
|
<dt>template-variable (3)</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<p>
|
<p>
|
||||||
A <a href="/docs/templates/user-variables.html">user variable</a>
|
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
|
<strong>Data 2: default</strong> - The default value of the
|
||||||
variable.
|
variable.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Data 3: required</strong> - If non-zero, then this variable
|
||||||
|
is required.
|
||||||
|
</p>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt>template-builder (2)</dt>
|
<dt>template-builder (2)</dt>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user