feat(01-03): add deterministic rich CLI output

- Inject bonfire.Output from stdin/stdout/stderr with stdlib widgets and x/term
- Degrade spinner, progress, table and prompts without a TTY or color
- Reject plugin command names that are not namespace:verb
This commit is contained in:
Jakub Zych
2026-09-16 13:54:44 +02:00
parent 9b1a25dc94
commit a6004e490f
16 changed files with 884 additions and 78 deletions

View File

@@ -3,8 +3,6 @@ package greeter
import (
"bytes"
"context"
"fmt"
"io"
"os"
"strings"
"testing"
@@ -15,17 +13,6 @@ import (
"git.golem15.com/golem15/summercms/pact"
)
type testOut struct{ bytes.Buffer }
func (o *testOut) Write(p []byte) (int, error) { return o.Buffer.Write(p) }
func (o *testOut) Println(a ...any) { fmt.Fprintln(&o.Buffer, a...) }
func (o *testOut) Printf(format string, a ...any) {
fmt.Fprintf(&o.Buffer, format, a...)
}
var _ bonfire.Output = (*testOut)(nil)
var _ io.Writer = (*testOut)(nil)
type extraMsg struct{ msg string }
func (e extraMsg) Message() string { return e.msg }
@@ -78,9 +65,10 @@ func runHelloCmd(t *testing.T, p *Plugin) string {
if len(cmds) == 0 {
t.Fatal("no commands")
}
var out testOut
if err := cmds[0].Run(context.Background(), nil, &out); err != nil {
var buf bytes.Buffer
out := bonfire.NewOutput(strings.NewReader(""), &buf, &buf)
if err := cmds[0].Run(context.Background(), nil, out); err != nil {
t.Fatalf("Run: %v", err)
}
return strings.TrimSpace(out.String())
return strings.TrimSpace(buf.String())
}