Skip to content

Commit

Permalink
Merge pull request #16 from AllanCapistrano/feat/navigate-edit-commit…
Browse files Browse the repository at this point in the history
…-message

Feat/navigate edit commit message
  • Loading branch information
AllanCapistrano authored Jul 20, 2023
2 parents 91f92e9 + 03e2f73 commit 00dd74f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
8 changes: 3 additions & 5 deletions cmd/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package cmd

import (
"fmt"
"os"
"log"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -107,14 +107,12 @@ are available.`,
example,
)
default:
fmt.Println("Could not find this type of confirmation! Try again.")
os.Exit(0)
log.Fatal("Could not find this type of confirmation! Try again.")
}

fmt.Println(commandHelp)
} else {
fmt.Println("You need to provide the commit type. For example: gbc help build")
os.Exit(0)
log.Fatal("You need to provide the commit type. For example: gbc help build")
}

},
Expand Down
20 changes: 5 additions & 15 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Copyright © 2023 Allan Capistrano <allan.capistrano3@gmail.com>
package cmd

import (
"bufio"
"fmt"
"log"
"os"
"os/exec"

Expand All @@ -14,6 +14,7 @@ import (
"github.com/spf13/cobra"

"github.com/allancapistrano/gbc/config"
"github.com/allancapistrano/user-input"
)

const GBC_VERSION = "1.0.0"
Expand Down Expand Up @@ -116,28 +117,17 @@ 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,
)

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.",
)
os.Exit(0)
log.Fatal("\nCould not create the commit! Make sure you have files to commit.")
}
}
},
Expand Down
10 changes: 4 additions & 6 deletions config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -87,14 +88,12 @@ func GetEmojis(fileName string, debug bool) Emoji {
if emojiSettingInString != "" {
err := json.Unmarshal([]byte(emojiSettingInString), &emojiSetting)
if err != nil {
fmt.Println("Unable to convert emoji settings to an expected type. Check the emoji settings in the config file.")
os.Exit(0)
log.Fatal("Unable to convert emoji settings to an expected type. Check the emoji settings in the config file.")
}
}

if err := scanner.Err(); err != nil {
fmt.Println("Couldn't read a line from the file.")
os.Exit(0)
log.Fatal("Couldn't read a line from the file.")
}

return emojiSetting
Expand Down Expand Up @@ -166,8 +165,7 @@ func EnableEmojis(fileName string, debug bool) bool {
}

if flagError {
fmt.Printf("Can't convert '%s' to bool type.", conversionError)
os.Exit(0)
log.Fatalf("Can't convert '%s' to bool type.", conversionError)
}

return enableEmojis
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ 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
)

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
)
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=

0 comments on commit 00dd74f

Please sign in to comment.