command: accept defaults for UI

This commit is contained in:
Mitchell Hashimoto 2014-09-29 13:51:16 -07:00
parent 99044a1f14
commit b32470f070
2 changed files with 14 additions and 1 deletions

View File

@ -79,6 +79,10 @@ func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) {
}
buf.WriteString("\n")
}
if opts.Default != "" {
buf.WriteString(" [bold]Default:[reset] ")
buf.WriteString(opts.Default)
}
buf.WriteString(" [bold]Enter a value:[reset] ")
// Ask the user for their input
@ -101,6 +105,11 @@ func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) {
select {
case line := <-result:
fmt.Fprint(w, "\n")
if line == "" {
line = opts.Default
}
return line, nil
case <-sigCh:
// Print a newline so that any further output starts properly

View File

@ -20,4 +20,8 @@ type InputOpts struct {
// that this will probably be in a terminal so split lines as you see
// necessary.
Description string
// Default will be the value returned if no data is entered.
Default string
DefaultHidden bool
}