diff --git a/data/int.go b/data/int.go new file mode 100644 index 0000000..1a5b191 --- /dev/null +++ b/data/int.go @@ -0,0 +1,14 @@ +package data + +import "time" + +const ( + startupTimeout = 200 * time.Millisecond + minAwaitTimeout = 100 * time.Millisecond + maxAwaitTimeout = 1 * time.Second +) + +type InteractiveShell interface { + init() error + execute() (string, error) +} diff --git a/data/int_shell.go b/data/int_basic.go similarity index 95% rename from data/int_shell.go rename to data/int_basic.go index 86d934c..fb8c31a 100644 --- a/data/int_shell.go +++ b/data/int_basic.go @@ -25,7 +25,11 @@ func (s *BasicInteractiveShell) init() error { cmd := exec.Command("sh", "-c", s.item.initScripts[0]) enrichEnvVariables(cmd, s.variables) - cmd.Wait() + + err := cmd.Wait() + if err != nil { + return err + } stdout, err := cmd.StdoutPipe() if err != nil { @@ -78,6 +82,10 @@ func (s *BasicInteractiveShell) init() error { func (s *BasicInteractiveShell) execute() (string, error) { + if s.stdin == nil { + return "", nil + } + _, err := io.WriteString(s.stdin, fmt.Sprintf(" %s\n", s.item.sampleScript)) if err != nil { s.errCount++ diff --git a/data/int_pty.go b/data/int_pty.go index 5585c3f..09e6b05 100644 --- a/data/int_pty.go +++ b/data/int_pty.go @@ -12,15 +12,6 @@ import ( "time" ) -const ( - startupTimeout = 200 * time.Millisecond - minAwaitTimeout = 100 * time.Millisecond - maxAwaitTimeout = 1 * time.Second -) - -/** - * Experimental - */ type PtyInteractiveShell struct { item *Item variables []string diff --git a/data/int_pty_windows.go b/data/int_pty_windows.go new file mode 100644 index 0000000..8a3b243 --- /dev/null +++ b/data/int_pty_windows.go @@ -0,0 +1,20 @@ +package data + +import ( + "errors" + "time" +) + +type PtyInteractiveShell struct { + item *Item + variables []string + timeout time.Duration +} + +func (s *PtyInteractiveShell) init() error { + return errors.New("PTY mode is not supported on Windows") +} + +func (s *PtyInteractiveShell) execute() (string, error) { + return "", errors.New("PTY mode is not supported on Windows") +} diff --git a/data/item.go b/data/item.go index d692cf0..b637110 100644 --- a/data/item.go +++ b/data/item.go @@ -18,8 +18,8 @@ type Item struct { color *ui.Color rateMs int pty bool - basicShell *BasicInteractiveShell - ptyShell *PtyInteractiveShell + basicShell InteractiveShell + ptyShell InteractiveShell } func NewItems(cfgs []config.Item, rateMs int) []*Item {