feat: convert entire CLI to clibase (#6491)

I'm sorry.
This commit is contained in:
Ammar Bandukwala
2023-03-23 17:42:20 -05:00
committed by GitHub
parent b71b8daa21
commit 2bd6d2908e
345 changed files with 9965 additions and 9082 deletions
+13 -3
View File
@@ -14,10 +14,12 @@ import (
"time"
"unicode/utf8"
"github.com/acarl005/stripansi"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"
"github.com/coder/coder/cli/clibase"
"github.com/coder/coder/pty"
"github.com/coder/coder/testutil"
)
@@ -116,8 +118,7 @@ func create(t *testing.T, ptty pty.PTY, name string) *PTY {
defer close(logDone)
s := bufio.NewScanner(logr)
for s.Scan() {
// Quote output to avoid terminal escape codes, e.g. bell.
tpty.logf("stdout: %q", s.Text())
tpty.logf("%q", stripansi.Strip(s.Text()))
}
}()
@@ -140,6 +141,15 @@ func (p *PTY) Close() error {
return p.close("close")
}
func (p *PTY) Attach(inv *clibase.Invocation) *PTY {
p.t.Helper()
inv.Stdout = p.Output()
inv.Stderr = p.Output()
inv.Stdin = p.Input()
return p
}
func (p *PTY) ExpectMatch(str string) string {
p.t.Helper()
@@ -173,7 +183,7 @@ func (p *PTY) ExpectMatchContext(ctx context.Context, str string) string {
p.fatalf("read error", "%v (wanted %q; got %q)", err, str, buffer.String())
return ""
}
p.logf("matched %q = %q", str, buffer.String())
p.logf("matched %q = %q", str, stripansi.Strip(buffer.String()))
return buffer.String()
}