2016-11-14 09:32:01 +01:00
|
|
|
// +build !solaris
|
|
|
|
|
|
|
|
// The readline library we use doesn't currently support solaris so
|
|
|
|
// we just build tag it off.
|
|
|
|
|
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
2021-01-20 19:18:02 +01:00
|
|
|
"github.com/hashicorp/terraform/internal/helper/wrappedreadline"
|
2021-05-17 18:39:14 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/repl"
|
2016-11-14 09:32:01 +01:00
|
|
|
|
|
|
|
"github.com/chzyer/readline"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *ConsoleCommand) modeInteractive(session *repl.Session, ui cli.Ui) int {
|
|
|
|
// Configure input
|
|
|
|
l, err := readline.NewEx(wrappedreadline.Override(&readline.Config{
|
|
|
|
Prompt: "> ",
|
|
|
|
InterruptPrompt: "^C",
|
|
|
|
EOFPrompt: "exit",
|
|
|
|
HistorySearchFold: true,
|
|
|
|
}))
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Error initializing console: %s",
|
|
|
|
err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
defer l.Close()
|
|
|
|
|
|
|
|
for {
|
|
|
|
// Read a line
|
|
|
|
line, err := l.Readline()
|
|
|
|
if err == readline.ErrInterrupt {
|
|
|
|
if len(line) == 0 {
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
} else if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2018-05-04 05:44:55 +02:00
|
|
|
out, exit, diags := session.Handle(line)
|
|
|
|
if diags.HasErrors() {
|
|
|
|
c.showDiagnostics(diags)
|
2016-11-14 09:32:01 +01:00
|
|
|
}
|
2018-05-04 05:44:55 +02:00
|
|
|
if exit {
|
|
|
|
break
|
2016-11-14 09:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ui.Output(out)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|