forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console_interactive.go
61 lines (51 loc) · 1.06 KB
/
console_interactive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// +build !solaris
// The readline library we use doesn't currently support solaris so
// we just build tag it off.
package command
import (
"fmt"
"io"
"github.com/hashicorp/terraform/helper/wrappedreadline"
"github.com/hashicorp/terraform/repl"
"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
}
out, err := session.Handle(line)
if err == repl.ErrSessionExit {
break
}
if err != nil {
ui.Error(err.Error())
continue
}
ui.Output(out)
}
return 0
}