Skip to content

Commit 3654952

Browse files
authored
feat: refactor command flags and add prompt-only mode (#185)
- Change `reviewCmd.Flags()` to `reviewCmd.PersistentFlags()` - Add a new flag `prompt_only` to show the prompt without sending a request to OpenAI - Modify error handling to check for `promptOnly` flag - Add logic to display the prompt when `promptOnly` is set Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent a9a6a5a commit 3654952

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

cmd/review.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ import (
1919
var maxTokens int
2020

2121
func init() {
22-
reviewCmd.Flags().IntVar(&diffUnified, "diff_unified", 3,
22+
reviewCmd.PersistentFlags().IntVar(&diffUnified, "diff_unified", 3,
2323
"generate diffs with <n> lines of context, default is 3")
24-
reviewCmd.Flags().IntVar(&maxTokens, "max_tokens", 300,
24+
reviewCmd.PersistentFlags().IntVar(&maxTokens, "max_tokens", 300,
2525
"the maximum number of tokens to generate in the chat completion.")
26-
reviewCmd.Flags().StringVar(&commitModel, "model", "gpt-3.5-turbo", "select openai model")
27-
reviewCmd.Flags().StringVar(&commitLang, "lang", "en", "summarizing language uses English by default")
28-
reviewCmd.Flags().StringSliceVar(&excludeList, "exclude_list", []string{}, "exclude file from git diff command")
29-
reviewCmd.Flags().BoolVar(&commitAmend, "amend", false,
26+
reviewCmd.PersistentFlags().StringVar(&commitModel, "model", "gpt-3.5-turbo", "select openai model")
27+
reviewCmd.PersistentFlags().StringVar(&commitLang, "lang", "en", "summarizing language uses English by default")
28+
reviewCmd.PersistentFlags().StringSliceVar(&excludeList, "exclude_list", []string{}, "exclude file from git diff command")
29+
reviewCmd.PersistentFlags().BoolVar(&commitAmend, "amend", false,
3030
"replace the tip of the current branch by creating a new commit.")
31+
reviewCmd.PersistentFlags().BoolVar(&promptOnly, "prompt_only", false,
32+
"show prompt only, don't send request to openai")
3133
}
3234

3335
var reviewCmd = &cobra.Command{
@@ -70,10 +72,18 @@ var reviewCmd = &cobra.Command{
7072
"file_diffs": diff,
7173
},
7274
)
73-
if err != nil {
75+
if err != nil && !promptOnly {
7476
return err
7577
}
7678

79+
// determine if the user wants to use the prompt only
80+
if promptOnly {
81+
color.Yellow("====================Prompt========================")
82+
color.Yellow("\n" + strings.TrimSpace(out) + "\n\n")
83+
color.Yellow("==================================================")
84+
return nil
85+
}
86+
7787
// Get summarize comment from diff datas
7888
color.Cyan("We are trying to review code changes")
7989
resp, err := client.Completion(cmd.Context(), out)

0 commit comments

Comments
 (0)