Skip to content

Commit

Permalink
Add support for reading input from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
koki-develop committed Sep 18, 2023
1 parent ecc1e0f commit c7aa7f8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bytes"
"errors"
"os"
"strings"
Expand Down Expand Up @@ -58,7 +59,22 @@ var rootCmd = &cobra.Command{
uicfg.Model = openai.GPT3Dot5Turbo
}

q := strings.Join(args, " ")
var q string
if len(args) > 0 {
q = strings.Join(args, " ")
} else {
info, err := os.Stdin.Stat()
if err != nil {
return err
}
if info.Mode()&os.ModeCharDevice == 0 {
b := new(bytes.Buffer)
if _, err := b.ReadFrom(os.Stdin); err != nil {
return err
}
q = b.String()
}
}
if q != "" {
uicfg.Question = &q
}
Expand Down

0 comments on commit c7aa7f8

Please sign in to comment.