Skip to content

Commit

Permalink
feat: allow ask to pass in stdin via -a -
Browse files Browse the repository at this point in the history
  • Loading branch information
yiblet committed Feb 6, 2024
1 parent 5dbecba commit a30e0cf
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ask_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type askCmd struct {
Temperature float32 `default:"0.7"`
Bash bool `arg:"--bash" help:"output only valid bash"`
Model string `arg:"--model,-m" help:"set openai model"`
Attach []string `arg:"--attach,-a,separate" help:"attach additional files at the end of the message"`
Attach []string `arg:"--attach,-a,separate" help:"attach additional files at the end of the message. pass '-' to pass in stdin"`
}

func (args *askCmd) buildContent(ctx context.Context) (string, error) {
Expand All @@ -51,12 +51,20 @@ func (args *askCmd) buildContent(ctx context.Context) (string, error) {

for _, a := range args.Attach {
sb.WriteRune('\n')
file, err := os.Open(a)
if err != nil {
return "", err

var file *os.File
if a == "-" {
file = os.Stdin
} else {
var err error
file, err = os.Open(a)
if err != nil {
return "", err
}
}
defer file.Close()
_, err = io.Copy(&sb, file)

_, err := io.Copy(&sb, file)
if err != nil {
return "", err
}
Expand Down

0 comments on commit a30e0cf

Please sign in to comment.