// no args, interactive, or question... read from stdin
// this is mainly for replacing text in vim
iflen(args)==0&&!PromptMode&&Question==""{
reader:=bufio.NewReader(os.Stdin)
varbufbytes.Buffer
@ -144,6 +152,7 @@ func main() {
}
PromptText+=buf.String()
}elseiflen(args)==1{
// if we have an arg, add it to the prompt
filename=args[0]
content,err:=os.ReadFile(filename)
iferr!=nil{
@ -153,14 +162,17 @@ func main() {
PromptText+=string(content)
}
// if there is a question, it comes last in the prompt
ifQuestion!=""{
PromptText+="\n"+Question
}
// interactive or file mode
ifPromptMode{
fmt.Println(PromptText)
err=RunPrompt(client)
}else{
// empty filename (no args) prints to stdout
err=RunOnce(client,filename)
}
@ -172,6 +184,7 @@ func main() {
},
}
// setup flags
rootCmd.Flags().StringVarP(&Question,"question","q","","ask a single question and print the response back")
rootCmd.Flags().StringVarP(&Pretext,"pretext","p","","pretext to add to ChatGPT input, use 'list' or 'view:<name>' to inspect predefined, '<name>' to use a pretext, or otherwise supply any custom text")
rootCmd.Flags().BoolVarP(&PromptMode,"interactive","i",false,"start an interactive session with ChatGPT")