From 130879390acf995869bb96d6befe321359bf4d36 Mon Sep 17 00:00:00 2001 From: Anthony Drendel Date: Mon, 2 Feb 2026 23:38:30 +0100 Subject: [PATCH 1/3] Default to speak if stdin has piped data --- cmd/root.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 6069591..14a506c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -52,6 +52,10 @@ func init() { // maybeDefaultToSpeak injects the "speak" subcommand when the user calls `sag` like macOS `say`. func maybeDefaultToSpeak() { if len(os.Args) <= 1 { + // Still default to speak if stdin has piped data + if !isStdinTTY() { + os.Args = append(os.Args, "speak") + } return } From b8b711df40a35feac09613631f37f43be841139d Mon Sep 17 00:00:00 2001 From: Anthony Drendel Date: Mon, 2 Feb 2026 23:44:03 +0100 Subject: [PATCH 2/3] Add test Fails without the fix --- cmd/root_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cmd/root_test.go b/cmd/root_test.go index 2ad30c8..49c1c17 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -113,3 +113,33 @@ func TestExecuteHelp(t *testing.T) { t.Fatalf("unreachable") } } + +func TestMaybeDefaultToSpeak_PipedStdin(t *testing.T) { + defer keepArgs(t)() + + // Replace stdin with a pipe (non-TTY) + origStdin := os.Stdin + r, w, err := os.Pipe() + if err != nil { + t.Fatalf("failed to create pipe: %v", err) + } + os.Stdin = r + defer func() { + os.Stdin = origStdin + r.Close() + w.Close() + }() + + os.Args = []string{"sag"} + maybeDefaultToSpeak() + + want := []string{"sag", "speak"} + if len(os.Args) != len(want) { + t.Fatalf("expected %v, got %v", want, os.Args) + } + for i := range want { + if os.Args[i] != want[i] { + t.Fatalf("args mismatch at %d: got %q want %q", i, os.Args[i], want[i]) + } + } +} From f27cce48c1903fba712a7ef9637b5515a405bb6b Mon Sep 17 00:00:00 2001 From: Anthony Drendel Date: Mon, 2 Feb 2026 23:47:44 +0100 Subject: [PATCH 3/3] Apply pull request comment --- cmd/root_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/root_test.go b/cmd/root_test.go index 49c1c17..95f8265 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -126,8 +126,8 @@ func TestMaybeDefaultToSpeak_PipedStdin(t *testing.T) { os.Stdin = r defer func() { os.Stdin = origStdin - r.Close() w.Close() + r.Close() }() os.Args = []string{"sag"}