(ctx *snap.Context, message string)
| 2732 | } |
| 2733 | |
| 2734 | func promptCommitConfirmation(ctx *snap.Context, message string) (string, bool, error) { |
| 2735 | current := message |
| 2736 | |
| 2737 | for { |
| 2738 | fmt.Fprintln(ctx.Stdout(), strings.Repeat("─", 60)) |
| 2739 | fmt.Fprintln(ctx.Stdout(), "Review commit message:") |
| 2740 | fmt.Fprintln(ctx.Stdout(), strings.Repeat("─", 60)) |
| 2741 | fmt.Fprintln(ctx.Stdout(), current) |
| 2742 | fmt.Fprintln(ctx.Stdout(), strings.Repeat("─", 60)) |
| 2743 | fmt.Fprintln(ctx.Stdout(), "Options: [y] commit [n] cancel [e] edit message") |
| 2744 | fmt.Fprint(ctx.Stdout(), "Choice [y/n/e]: ") |
| 2745 | |
| 2746 | choice, err := readConfirmationChoice(ctx) |
| 2747 | if err != nil { |
| 2748 | return "", false, fmt.Errorf("reading choice: %w", err) |
| 2749 | } |
| 2750 | |
| 2751 | switch strings.ToLower(string(choice)) { |
| 2752 | case "y": |
| 2753 | return current, true, nil |
| 2754 | case "n": |
| 2755 | return current, false, nil |
| 2756 | case "e": |
| 2757 | edited, err := editCommitMessage(ctx, current) |
| 2758 | if err != nil { |
| 2759 | return "", false, fmt.Errorf("edit commit message: %w", err) |
| 2760 | } |
| 2761 | trimmed := strings.TrimSpace(edited) |
| 2762 | if trimmed == "" { |
| 2763 | fmt.Fprintln(ctx.Stdout(), "Edited message is empty; keeping previous message.") |
| 2764 | continue |
| 2765 | } |
| 2766 | current = trimmed |
| 2767 | default: |
| 2768 | fmt.Fprintln(ctx.Stdout(), "Please choose y, n, or e.") |
| 2769 | } |
| 2770 | } |
| 2771 | } |
| 2772 | |
| 2773 | func editCommitMessage(ctx *snap.Context, current string) (string, error) { |
| 2774 | tmpFile, err := os.CreateTemp("", commandName+"-commit-*.md") |
no test coverage detected