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

View File

@ -11,7 +11,7 @@ type UIInput interface {
type InputOpts struct { type InputOpts struct {
// Id is a unique ID for the question being asked that might be // Id is a unique ID for the question being asked that might be
// used for logging or to look up a prior answered question. // 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 is a human-friendly question for inputting this value.
Query string Query string
@ -20,4 +20,8 @@ type InputOpts struct {
// that this will probably be in a terminal so split lines as you see // that this will probably be in a terminal so split lines as you see
// necessary. // necessary.
Description string Description string
// Default will be the value returned if no data is entered.
Default string
DefaultHidden bool
} }