diff --git a/command/meta.go b/command/meta.go index ca1189066..005d60a29 100644 --- a/command/meta.go +++ b/command/meta.go @@ -133,7 +133,9 @@ func (m *Meta) contextOpts() *terraform.ContextOpts { vs[k] = v } opts.Variables = vs - opts.UIInput = new(UIInput) + opts.UIInput = &UIInput{ + Colorize: m.Colorize(), + } return &opts } diff --git a/command/ui_input.go b/command/ui_input.go index d37bde442..bf7f711d8 100644 --- a/command/ui_input.go +++ b/command/ui_input.go @@ -1,15 +1,19 @@ package command import ( + "bufio" + "bytes" "errors" "fmt" "io" "log" "os" "os/signal" + "strings" "sync" "github.com/hashicorp/terraform/terraform" + "github.com/mitchellh/colorstring" ) var defaultInputReader io.Reader @@ -18,6 +22,9 @@ var defaultInputWriter io.Writer // UIInput is an implementation of terraform.UIInput that asks the CLI // for input stdin. type UIInput struct { + // Colorize will color the output. + Colorize *colorstring.Colorize + // Reader and Writer for IO. If these aren't set, they will default to // Stdout and Stderr respectively. Reader io.Reader @@ -25,9 +32,12 @@ type UIInput struct { interrupted bool l sync.Mutex + once sync.Once } func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) { + i.once.Do(i.init) + r := i.Reader w := i.Writer if r == nil { @@ -58,8 +68,21 @@ func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) { signal.Notify(sigCh, os.Interrupt) defer signal.Stop(sigCh) + // Build the output format for asking + var buf bytes.Buffer + buf.WriteString("[reset]") + buf.WriteString(fmt.Sprintf("[bold]%s[reset]\n", opts.Query)) + if opts.Description != "" { + s := bufio.NewScanner(strings.NewReader(opts.Description)) + for s.Scan() { + buf.WriteString(fmt.Sprintf(" %s\n", s.Text())) + } + buf.WriteString("\n") + } + buf.WriteString(" [bold]Enter a value:[reset] ") + // Ask the user for their input - if _, err := fmt.Fprint(w, opts.Query); err != nil { + if _, err := fmt.Fprint(w, i.Colorize.Color(buf.String())); err != nil { return "", err } @@ -89,3 +112,12 @@ func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) { return "", errors.New("interrupted") } } + +func (i *UIInput) init() { + if i.Colorize == nil { + i.Colorize = &colorstring.Colorize{ + Colors: colorstring.DefaultColors, + Disable: true, + } + } +} diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 9cd952930..371a320b2 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -616,7 +616,7 @@ func (m schemaMap) inputString( schema *Schema) (interface{}, error) { result, err := input.Input(&terraform.InputOpts{ Id: k, - Query: fmt.Sprintf("%s: ", k), + Query: k, }) return result, err diff --git a/terraform/context.go b/terraform/context.go index dd9a5369e..35f1dd493 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -166,9 +166,8 @@ func (c *Context) Input() error { for { var err error value, err = c.uiInput.Input(&InputOpts{ - Id: fmt.Sprintf("var.%s", n), - Query: fmt.Sprintf( - "Variable '%s': ", n), + Id: fmt.Sprintf("var.%s", n), + Query: fmt.Sprintf("var.%s", n), }) if err != nil { return fmt.Errorf( diff --git a/terraform/ui_input.go b/terraform/ui_input.go index 46f6378d1..5b2ad4897 100644 --- a/terraform/ui_input.go +++ b/terraform/ui_input.go @@ -15,4 +15,9 @@ type InputOpts struct { // Query is a human-friendly question for inputting this value. Query string + + // Description is a description about what this option is. Be wary + // that this will probably be in a terminal so split lines as you see + // necessary. + Description string }