Skip to content

Commit fc8c950

Browse files
committed
Cleanup readwriter
1 parent def36fa commit fc8c950

File tree

6 files changed

+15
-32
lines changed

6 files changed

+15
-32
lines changed

cli/login_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
func TestLogin(t *testing.T) {
1515
t.Parallel()
16-
1716
t.Run("InitialUserNoTTY", func(t *testing.T) {
1817
t.Parallel()
1918
client := coderdtest.New(t, nil)
@@ -29,7 +28,7 @@ func TestLogin(t *testing.T) {
2928
// accurately detect Windows ptys when they are not attached to a process:
3029
// https://github.com/mattn/go-isatty/issues/59
3130
doneChan := make(chan struct{})
32-
root, _ := clitest.New(t, "login", client.URL.String())
31+
root, _ := clitest.New(t, "login", "--force-tty", client.URL.String())
3332
pty := ptytest.New(t)
3433
root.SetIn(pty.Input())
3534
root.SetOut(pty.Output())
@@ -61,7 +60,7 @@ func TestLogin(t *testing.T) {
6160
coderdtest.CreateFirstUser(t, client)
6261

6362
doneChan := make(chan struct{})
64-
root, _ := clitest.New(t, "login", client.URL.String(), "--no-open")
63+
root, _ := clitest.New(t, "login", "--force-tty", client.URL.String(), "--no-open")
6564
pty := ptytest.New(t)
6665
root.SetIn(pty.Input())
6766
root.SetOut(pty.Output())

cli/projectcreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func projectCreate() *cobra.Command {
3030
provisioner string
3131
)
3232
cmd := &cobra.Command{
33-
Use: "create",
33+
Use: "create <name>",
3434
Short: "Create a project from the current directory",
3535
RunE: func(cmd *cobra.Command, args []string) error {
3636
client, err := createClient(cmd)

cli/root.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/coder/coder/cli/cliui"
1414
"github.com/coder/coder/cli/config"
1515
"github.com/coder/coder/codersdk"
16-
"github.com/coder/coder/pty"
1716
)
1817

1918
var (
@@ -142,10 +141,6 @@ func isTTY(cmd *cobra.Command) bool {
142141
if forceTty && err == nil {
143142
return true
144143
}
145-
_, ok := cmd.InOrStdin().(pty.ReadWriter)
146-
if ok {
147-
return true
148-
}
149144
file, ok := cmd.InOrStdin().(*os.File)
150145
if !ok {
151146
return false

pty/pty.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ type PTY interface {
1414
// uses the output stream for writing.
1515
//
1616
// The same stream could be read to validate output.
17-
Output() ReadWriter
17+
Output() io.ReadWriter
1818

1919
// Input handles TTY input.
2020
//
2121
// cmd.SetInput(pty.Input()) would be used to specify a command
2222
// uses the PTY input for reading.
2323
//
2424
// The same stream would be used to provide user input: pty.Input().Write(...)
25-
Input() ReadWriter
25+
Input() io.ReadWriter
2626

2727
// Resize sets the size of the PTY.
2828
Resize(cols uint16, rows uint16) error
@@ -33,10 +33,7 @@ func New() (PTY, error) {
3333
return newPty()
3434
}
3535

36-
// ReadWriter implements io.ReadWriter, but is intentionally avoids
37-
// using the interface to allow for direct access to the reader or
38-
// writer. This is to enable a caller to grab file descriptors.
39-
type ReadWriter struct {
36+
type readWriter struct {
4037
io.Reader
4138
io.Writer
4239
}

pty/pty_other.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
package pty
55

66
import (
7+
"io"
78
"os"
89
"sync"
910

1011
"github.com/creack/pty"
11-
"github.com/muesli/cancelreader"
1212
)
1313

1414
func newPty() (PTY, error) {
@@ -28,15 +28,15 @@ type otherPty struct {
2828
pty, tty *os.File
2929
}
3030

31-
func (p *otherPty) Input() ReadWriter {
32-
return ReadWriter{
31+
func (p *otherPty) Input() io.ReadWriter {
32+
return readWriter{
3333
Reader: p.tty,
3434
Writer: p.pty,
3535
}
3636
}
3737

38-
func (p *otherPty) Output() ReadWriter {
39-
return ReadWriter{
38+
func (p *otherPty) Output() io.ReadWriter {
39+
return readWriter{
4040
Reader: p.pty,
4141
Writer: p.tty,
4242
}
@@ -66,7 +66,3 @@ func (p *otherPty) Close() error {
6666
}
6767
return nil
6868
}
69-
70-
func (rw ReadWriter) CancelReader() (cancelreader.CancelReader, error) {
71-
return cancelreader.NewReader(rw.Reader)
72-
}

pty/pty_windows.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ type ptyWindows struct {
6767
closed bool
6868
}
6969

70-
func (p *ptyWindows) Output() ReadWriter {
71-
return ReadWriter{
70+
func (p *ptyWindows) Output() io.ReadWriter {
71+
return readWriter{
7272
Reader: p.outputRead,
7373
Writer: p.outputWrite,
7474
}
7575
}
7676

77-
func (p *ptyWindows) Input() ReadWriter {
78-
return ReadWriter{
77+
func (p *ptyWindows) Input() io.ReadWriter {
78+
return readWriter{
7979
Reader: p.inputRead,
8080
Writer: p.inputWrite,
8181
}
@@ -108,7 +108,3 @@ func (p *ptyWindows) Close() error {
108108

109109
return nil
110110
}
111-
112-
func (rw ReadWriter) CancelReader() (cancelreader.CancelReader, error) {
113-
return nil, xerrors.New("not implemented")
114-
}

0 commit comments

Comments
 (0)