diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 56ec9a4..2e75ec6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ permissions: jobs: goreleaser: - runs-on: self-hosted + runs-on: ubuntu-latest steps: - name: Checkout diff --git a/src/.goreleaser.yml b/src/.goreleaser.yml index 73295f5..d638118 100644 --- a/src/.goreleaser.yml +++ b/src/.goreleaser.yml @@ -11,7 +11,8 @@ builds: - CGO_ENABLED=0 flags: - -mod=vendor - + ldflags: + - -s -w -X main.version={{.Version}} release: prerelease: auto diff --git a/src/cmd/goji.go b/src/cmd/goji.go index d546f71..bb26274 100644 --- a/src/cmd/goji.go +++ b/src/cmd/goji.go @@ -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 { @@ -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 {