Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/helpflag
Browse files Browse the repository at this point in the history
  • Loading branch information
muandane authored Nov 13, 2023
2 parents 4ff49a0 + 932dd7a commit abcef4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:

jobs:
goreleaser:
runs-on: ubuntu-latest
runs-on: self-hosted
steps:
-
name: Checkout
Expand Down
3 changes: 1 addition & 2 deletions src/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ builds:
- CGO_ENABLED=0
flags:
- -mod=vendor
ldflags:
- -s -w -X main.version={{.Version}}

release:
prerelease: auto

Expand Down
88 changes: 18 additions & 70 deletions src/cmd/goji.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
"github.com/fatih/color"
)

func init() {
}

var (
version = ""
)

func init() {
}

func main() {

helpFlag := flag.Bool("h", false, "Display help information")
Expand All @@ -30,12 +30,6 @@ func main() {
flag.BoolVar(versionFlag, "version", false, "display help")
initFlag := flag.Bool("i", false, "Generate a configuration file")
flag.BoolVar(initFlag, "init", false, "display help")
typeFlag := flag.String("t", "", "Specify the type from the config file")
scopeFlag := flag.String("s", "", "Specify a custom scope")
messageFlag := flag.String("m", "", "Specify a commit message")
flag.StringVar(typeFlag, "type", "", "Specify the type from the config file")
flag.StringVar(scopeFlag, "scope", "", "Specify a custom scope")
flag.StringVar(messageFlag, "message", "", "Specify a commit message")

flag.Parse()
if *helpFlag {
Expand Down Expand Up @@ -86,69 +80,23 @@ func main() {
return
}

if *typeFlag != "" && *messageFlag != "" {
config, err := config.LoadConfig(".goji.json")
if err != nil {
log.Fatalf(color.YellowString("Error loading config file: %v"), err)
}
var typeMatch string
for _, t := range config.Types {
if *typeFlag == t.Name {
typeMatch = fmt.Sprintf("%s %s", t.Name, t.Emoji)
break
}
}

// If no match was found, use the type flag as is
if typeMatch == "" {
typeMatch = *typeFlag
}

// Construct the commit message from the flags
commitMessage := *messageFlag
if typeMatch != "" {
commitMessage = fmt.Sprintf("%s: %s", typeMatch, commitMessage)
if *scopeFlag != "" {
commitMessage = fmt.Sprintf("%s(%s): %s", typeMatch, *scopeFlag, *messageFlag)
}
}

// Create the git commit command with the commit message
cmd := exec.Command("git", "commit", "-m", commitMessage)

// Run the command and capture the output and any error
output, err := cmd.CombinedOutput()

// Check if the command resulted in an error
if err != nil {
// If there was an error, print it and the output from the command
fmt.Printf(color.MagentaString("Error executing git commit: %v\n"), err)
fmt.Println("Git commit output: ", string(output))
return
}

// If there was no error, print the output from the command
fmt.Printf("Git commit output: %s\n", string(output))
} else {
// If not all flags were provided, fall back to your existing interactive prompt logic
config, err := config.LoadConfig(".goji.json")
if err != nil {
log.Fatalf(color.YellowString("Error loading config file: %v"), err)
}
config, err := config.LoadConfig(".goji.json")
if err != nil {
log.Fatalf(color.YellowString("Error loading config file: %v"), err)
}

commitMessage, err := utils.AskQuestions(config)
if err != nil {
log.Fatalf(color.YellowString("Error asking questions: %v"), err)
}
cmd := exec.Command("git", "commit", "-m", commitMessage)
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf(color.MagentaString("Error executing git commit: %v\n"), err)
fmt.Println("Git commit output: ", string(output))
return
}
fmt.Printf("Git commit output: %s\n", string(output))
commitMessage, err := utils.AskQuestions(config)
if err != nil {
log.Fatalf(color.YellowString("Error asking questions: %v"), err)
}
cmd := exec.Command("git", "commit", "-m", commitMessage)
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf(color.MagentaString("Error executing git commit: %v\n"), err)
fmt.Println("Git commit output: ", string(output))
return
}
fmt.Printf("Git commit output: %s\n", string(output))
}

type Gitmoji struct {
Expand Down

0 comments on commit abcef4f

Please sign in to comment.