Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/flags #13

Merged
merged 4 commits into from
Nov 13, 2023
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
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: self-hosted
runs-on: ubuntu-latest
steps:
-
name: Checkout
Expand Down
3 changes: 2 additions & 1 deletion src/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ builds:
- CGO_ENABLED=0
flags:
- -mod=vendor

ldflags:
- -s -w -X main.version={{.Version}}
release:
prerelease: auto

Expand Down
89 changes: 73 additions & 16 deletions src/cmd/goji.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ import (
func init() {
}

var (
version = ""
)

func main() {
version := "0.0.1-rc4"


helpFlag := flag.Bool("h", false, "Display help information")
flag.BoolVar(helpFlag, "help", false, "display help")
versionFlag := flag.Bool("v", false, "Display version information")
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 @@ -73,23 +84,69 @@ func main() {
return
}

config, err := config.LoadConfig(".goji.json")
if err != nil {
log.Fatalf(color.YellowString("Error loading config file: %v"), err)
}
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
}
}

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
// 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)
}

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))
}
fmt.Printf("Git commit output: %s\n", string(output))
}

type Gitmoji struct {
Expand Down
Loading