Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changesets/patch-1788520819013459586.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Migrate description input to chzyer/readline to fix multi-print pasting bugs, add interrupt handling for clean exits, and resolve filepath variable shadowing.
33 changes: 26 additions & 7 deletions changeset/changeset.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package changeset

import (
"bufio"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"time"

"github.com/ChanduBobbili/changesetgoo/constants"
"github.com/ChanduBobbili/changesetgoo/enums"
"github.com/chzyer/readline"
"github.com/manifoldco/promptui"
)

Expand All @@ -22,6 +24,10 @@ func PromptReleaseType() (enums.ReleaseType, error) {

_, result, err := prompt.Run()
if err != nil {
// Handle graceful shutdown for Ctrl+C and Ctrl+D
if errors.Is(err, promptui.ErrInterrupt) || errors.Is(err, promptui.ErrEOF) {
os.Exit(0)
}
return "", err
}

Expand All @@ -35,11 +41,11 @@ func AddChangeset(releaseType enums.ReleaseType, message string) error {
}

filename := fmt.Sprintf("%s-%d.md", releaseType, time.Now().UnixNano())
filepath := filepath.Join(constants.ChangesDir, filename)
filePath := filepath.Join(constants.ChangesDir, filename)

// Only write the plain description (no headings, no "###")
// Only write the plain description (no headings, no "###")
content := strings.TrimSpace(message) + "\n"
return os.WriteFile(filepath, []byte(content), 0644)
return os.WriteFile(filePath, []byte(content), 0644)
}

// InteractiveAdd allows user to input bump type and description
Expand All @@ -49,9 +55,22 @@ func InteractiveAdd() error {
return err
}

fmt.Print("Enter change description: ")
reader := bufio.NewReader(os.Stdin)
desc, _ := reader.ReadString('\n')
// Use readline directly to fix the multi-print pasting bug
rl, err := readline.New("Enter change description: ")
if err != nil {
return err
}
defer rl.Close()

desc, err := rl.Readline()
if err != nil {
// Handle graceful shutdown for Ctrl+C and Ctrl+D during text input
if errors.Is(err, readline.ErrInterrupt) || errors.Is(err, io.EOF) {
os.Exit(0)
}
return err
}

desc = strings.TrimSpace(desc)

if err := AddChangeset(bump, desc); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ go 1.25.1
require github.com/manifoldco/promptui v0.9.0

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b // indirect
github.com/chzyer/readline v1.5.1 // indirect
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Loading