diff --git a/cmd/root.go b/cmd/root.go index f507e4a..0113b28 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,7 +4,6 @@ Copyright © 2023 Allan Capistrano package cmd import ( - "bufio" "fmt" "os" "os/exec" @@ -14,6 +13,7 @@ import ( "github.com/spf13/cobra" "github.com/allancapistrano/gbc/config" + "github.com/allancapistrano/user-input" ) const GBC_VERSION = "1.0.0" @@ -116,15 +116,7 @@ simple way to write commits following the Conventional Commits ) } - buffer := bufio.NewReader(os.Stdin) - - fmt.Print("What commit message do you want? ") - - commitMessage, err := buffer.ReadString('\n') - if err != nil { - fmt.Println("Unable to read commit message! Try again.") - os.Exit(0) - } + commitMessage := userinput.GetUserInput("What commit message do you want? ", true) commandString := fmt.Sprintf( `git commit -m "%s: %s"`, commitType, commitMessage, @@ -132,7 +124,7 @@ simple way to write commits following the Conventional Commits command := exec.Command("/bin/bash", "-c", commandString) - err = command.Run() + err := command.Run() if err != nil { fmt.Println( "\nCould not create the commit! Make sure you have files to commit.", diff --git a/go.mod b/go.mod index ac7bf6b..abf2dcb 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/allancapistrano/gbc go 1.20 require ( + github.com/allancapistrano/user-input v1.1.1 github.com/kyokomi/emoji/v2 v2.2.12 github.com/nexidian/gocliselect v1.0.0 github.com/spf13/cobra v1.7.0 @@ -10,8 +11,9 @@ require ( require ( github.com/buger/goterm v1.0.4 // indirect + github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/pkg/term v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/sys v0.0.0-20211015200801-69063c4bb744 // indirect + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect ) diff --git a/go.sum b/go.sum index 368a8c1..c036cdb 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,10 @@ +github.com/allancapistrano/user-input v1.1.1 h1:9j/3qLHHl9hLkBXZLJwGqsa8p/9FWMcaiZYWX6PgHns= +github.com/allancapistrano/user-input v1.1.1/go.mod h1:Pq0pSXYv417hEe2Bha44qY/Z1xm36Au0NhowDWpo2ak= github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY= github.com/buger/goterm v1.0.4/go.mod h1:HiFWV3xnkolgrBV3mY8m0X0Pumt4zg4QhbdOzQtB8tE= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 h1:XBBHcIb256gUJtLmY22n99HaZTz+r2Z51xUPi01m3wg= +github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203/go.mod h1:E1jcSv8FaEny+OP/5k9UxZVw9YFWGj7eI4KR/iOBqCg= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/kyokomi/emoji/v2 v2.2.12 h1:sSVA5nH9ebR3Zji1o31wu3yOwD1zKXQA2z0zUyeit60= @@ -16,7 +20,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20211015200801-69063c4bb744 h1:KzbpndAYEM+4oHRp9JmB2ewj0NHHxO3Z0g7Gus2O1kk= -golang.org/x/sys v0.0.0-20211015200801-69063c4bb744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=