Skip to content

Commit

Permalink
🤖 Plandex → Enhance doTell function to support piped input and stdin …
Browse files Browse the repository at this point in the history
…reading.

fixes #162
  • Loading branch information
danenania committed Oct 2, 2024
1 parent 6b2dacb commit 80dea78
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/cli/cmd/tell.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"bufio"
"fmt"
"io"
"os"
"os/exec"
"plandex/auth"
Expand Down Expand Up @@ -43,7 +45,6 @@ func init() {
}

func doTell(cmd *cobra.Command, args []string) {

auth.MustResolveAuthWithOrg()
lib.MustResolveProject()

Expand All @@ -67,7 +68,22 @@ func doTell(cmd *cobra.Command, args []string) {
}
prompt = string(bytes)
} else {
prompt = getEditorPrompt()
// Check if there's piped input
fileInfo, err := os.Stdin.Stat()
if err != nil {
term.OutputErrorAndExit("Failed to stat stdin: %v", err)
}

if fileInfo.Mode()&os.ModeNamedPipe != 0 {
reader := bufio.NewReader(os.Stdin)
pipedData, err := io.ReadAll(reader)
if err != nil {
term.OutputErrorAndExit("Failed to read piped data: %v", err)
}
prompt = string(pipedData)
} else {
prompt = getEditorPrompt()
}
}

if prompt == "" {
Expand Down

0 comments on commit 80dea78

Please sign in to comment.