mirror of https://github.com/hashicorp/terraform
The readline library doesn't support Solaris. For now, we'll just not support console there.pull/10093/head
parent
0232b39db6
commit
1a6056b287
@ -0,0 +1,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
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
// +build solaris
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/repl"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func (c *ConsoleCommand) modeInteractive(session *repl.Session, ui cli.Ui) int {
|
||||
ui.Error(fmt.Sprintf(
|
||||
"The readline library Terraform currently uses for the interactive\n" +
|
||||
"console is not supported by Solaris. Interactive mode is therefore\n" +
|
||||
"not supported on Solaris currently."))
|
||||
return 1
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
// Package wrappedstreams provides access to the standard OS streams
|
||||
// (stdin, stdout, stderr) even if wrapped under panicwrap.
|
||||
package wrappedstreams
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/mitchellh/panicwrap"
|
||||
)
|
||||
|
||||
// Stdin returns the true stdin of the process.
|
||||
func Stdin() *os.File {
|
||||
stdin := os.Stdin
|
||||
if panicwrap.Wrapped(nil) {
|
||||
stdin = wrappedStdin
|
||||
}
|
||||
|
||||
return stdin
|
||||
}
|
||||
|
||||
// Stdout returns the true stdout of the process.
|
||||
func Stdout() *os.File {
|
||||
stdout := os.Stdout
|
||||
if panicwrap.Wrapped(nil) {
|
||||
stdout = wrappedStdout
|
||||
}
|
||||
|
||||
return stdout
|
||||
}
|
||||
|
||||
// Stderr returns the true stderr of the process.
|
||||
func Stderr() *os.File {
|
||||
stderr := os.Stderr
|
||||
if panicwrap.Wrapped(nil) {
|
||||
stderr = wrappedStderr
|
||||
}
|
||||
|
||||
return stderr
|
||||
}
|
||||
|
||||
// These are the wrapped streams. There doesn't appear to be a negative
|
||||
// impact of opening these files even if the file descriptor doesn't exist.
|
||||
var (
|
||||
wrappedStdin = os.NewFile(uintptr(3), "stdin")
|
||||
wrappedStdout = os.NewFile(uintptr(4), "stdout")
|
||||
wrappedStderr = os.NewFile(uintptr(5), "stderr")
|
||||
)
|
||||
Loading…
Reference in new issue