Skip to content

Commit c3da45c

Browse files
committed
chore: use mattn/go-isatty instead
1 parent 31d50c2 commit c3da45c

File tree

2 files changed

+2
-50
lines changed

2 files changed

+2
-50
lines changed

cmd/server/server.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sort"
1212
"strings"
1313

14+
"github.com/mattn/go-isatty"
1415
"github.com/spf13/cobra"
1516
"github.com/spf13/viper"
1617
"golang.org/x/xerrors"
@@ -71,11 +72,6 @@ func parseAgentType(firstArg string, agentTypeVar string) (AgentType, error) {
7172
return AgentTypeCustom, nil
7273
}
7374

74-
// isStdinPiped checks if stdin is piped (not a terminal)
75-
func isStdinPiped(stat os.FileInfo) bool {
76-
return (stat.Mode() & os.ModeCharDevice) == 0
77-
}
78-
7975
func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) error {
8076
agent := argsToPass[0]
8177
agentTypeValue := viper.GetString(FlagType)
@@ -97,7 +93,7 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
9793
// Read stdin if it's piped, to be used as initial prompt
9894
initialPrompt := viper.GetString(FlagInitialPrompt)
9995
if initialPrompt == "" {
100-
if stat, err := os.Stdin.Stat(); err == nil && isStdinPiped(stat) {
96+
if !isatty.IsTerminal(os.Stdin.Fd()) {
10197
if stdinData, err := io.ReadAll(os.Stdin); err != nil {
10298
return xerrors.Errorf("failed to read stdin: %w", err)
10399
} else if len(stdinData) > 0 {

cmd/server/server_test.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"os"
66
"strings"
77
"testing"
8-
"time"
98

109
"github.com/spf13/cobra"
1110
"github.com/spf13/viper"
@@ -572,46 +571,3 @@ func TestServerCmd_AllowedOrigins(t *testing.T) {
572571
})
573572
}
574573
}
575-
576-
func TestIsStdinPiped(t *testing.T) {
577-
tests := []struct {
578-
name string
579-
fileInfo os.FileInfo
580-
expected bool
581-
}{
582-
{
583-
name: "regular file (piped)",
584-
fileInfo: &mockFileInfo{mode: 0},
585-
expected: true,
586-
},
587-
{
588-
name: "character device (terminal)",
589-
fileInfo: &mockFileInfo{mode: os.ModeCharDevice},
590-
expected: false,
591-
},
592-
{
593-
name: "named pipe",
594-
fileInfo: &mockFileInfo{mode: os.ModeNamedPipe},
595-
expected: true,
596-
},
597-
}
598-
599-
for _, tt := range tests {
600-
t.Run(tt.name, func(t *testing.T) {
601-
result := isStdinPiped(tt.fileInfo)
602-
assert.Equal(t, tt.expected, result)
603-
})
604-
}
605-
}
606-
607-
// mockFileInfo implements os.FileInfo for testing
608-
type mockFileInfo struct {
609-
mode os.FileMode
610-
}
611-
612-
func (m *mockFileInfo) Name() string { return "stdin" }
613-
func (m *mockFileInfo) Size() int64 { return 0 }
614-
func (m *mockFileInfo) Mode() os.FileMode { return m.mode }
615-
func (m *mockFileInfo) ModTime() time.Time { return time.Time{} }
616-
func (m *mockFileInfo) IsDir() bool { return false }
617-
func (m *mockFileInfo) Sys() interface{} { return nil }

0 commit comments

Comments
 (0)