Skip to content

Commit 0396a59

Browse files
authored
feat: add noConfirm flag to streamline commit process (#189)
- Add a `noConfirm` flag to skip the confirmation prompt - Modify `commitCmd` to check for `noConfirm` flag in preview mode - Update `prepare-commit-msg` template to include `--no_confirm` flag in `codegpt commit` command Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 6f5ce01 commit 0396a59

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

cmd/commit.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var (
4040
templateVarsFile string
4141

4242
defaultTimeout = 30 * time.Second
43+
noConfirm = false
4344
)
4445

4546
func init() {
@@ -62,9 +63,12 @@ func init() {
6263
commitCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "t", defaultTimeout, "request timeout")
6364
commitCmd.PersistentFlags().BoolVar(&promptOnly, "prompt_only", false,
6465
"show prompt only, don't send request to openai")
66+
commitCmd.PersistentFlags().BoolVar(&noConfirm, "no_confirm", false,
67+
"skip confirmation prompt")
6568
_ = viper.BindPFlag("output.file", commitCmd.PersistentFlags().Lookup("file"))
6669
}
6770

71+
// commitCmd represents the commit command.
6872
var commitCmd = &cobra.Command{
6973
Use: "commit",
7074
Short: "Auto generate commit message",
@@ -287,7 +291,7 @@ var commitCmd = &cobra.Command{
287291
return err
288292
}
289293

290-
if preview {
294+
if preview && !noConfirm {
291295
input := confirmation.New("Commit preview summary?", confirmation.Yes)
292296
ready, err := input.RunPrompt()
293297
if err != nil {
@@ -298,18 +302,20 @@ var commitCmd = &cobra.Command{
298302
}
299303
}
300304

301-
input := confirmation.New("Do you want to change the commit message?", confirmation.No)
302-
change, err := input.RunPrompt()
303-
if err != nil {
304-
return err
305-
}
306-
307-
if change {
308-
p := tea.NewProgram(initialPrompt(commitMessage))
309-
if _, err := p.Run(); err != nil {
305+
if !noConfirm {
306+
input := confirmation.New("Do you want to change the commit message?", confirmation.No)
307+
change, err := input.RunPrompt()
308+
if err != nil {
310309
return err
311310
}
312-
p.Wait()
311+
312+
if change {
313+
p := tea.NewProgram(initialPrompt(commitMessage))
314+
if _, err := p.Run(); err != nil {
315+
return err
316+
}
317+
p.Wait()
318+
}
313319
}
314320

315321
// git commit automatically

git/templates/prepare-commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22

33
if [[ "$2" != "message" && "$2" != "commit" ]]; then
4-
codegpt commit --file $1 --preview
4+
codegpt commit --file $1 --preview --no_confirm
55
fi

0 commit comments

Comments
 (0)