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

@ -11,7 +11,7 @@ type UIInput interface {
type InputOpts struct {
// Id is a unique ID for the question being asked that might be
// used for logging or to look up a prior answered question.
Id string
Id string
// Query is a human-friendly question for inputting this value.
Query string
@ -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
}