From aafba935c31fea2d296b8a90eecfd6d6c4597dbb Mon Sep 17 00:00:00 2001 From: Slug-Boi Date: Wed, 9 Apr 2025 21:01:19 +0200 Subject: [PATCH] refactor: error handling and add flags to git push command --- src/cmd/cz.go | 17 +++++++++++++++-- src/cmd/root.go | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/cmd/cz.go b/src/cmd/cz.go index 7c33774..31faff0 100644 --- a/src/cmd/cz.go +++ b/src/cmd/cz.go @@ -27,6 +27,7 @@ This will require the user to have commitizen installed on their system.`, cflag, _ := cmd.Flags().GetBool("cli") gflag, _ := cmd.Flags().GetString("git") gpflag, _ := cmd.Flags().GetBool("git-push") + gpflagsflag, _ := cmd.Flags().GetString("git-push-flags") // run execute commands again as root run will not call this part message = utils.Cz_Call() @@ -53,7 +54,10 @@ This will require the user to have commitizen installed on their system.`, if gflag != "" { git_flags = strings.Split(gflag, " ") } - utils.GitWrapper(message, git_flags) + err := utils.GitWrapper(message, git_flags) + if err != nil { + fmt.Println("Error committing:", err) + } if update { update_msg() @@ -63,8 +67,16 @@ This will require the user to have commitizen installed on their system.`, fmt.Println(message) } + var gp_flags []string + if gpflagsflag != "" { + gp_flags = strings.Split(gpflagsflag, " ") + } + if gpflag { - utils.GitPush() + err := utils.GitPush(gp_flags) + if err != nil { + fmt.Println("Error pushing to git:", err) + } } }, } @@ -75,4 +87,5 @@ func init() { czCmd.Flags().BoolP("print-output", "o", false, "Print the commit message") czCmd.Flags().BoolP("cli", "c", false, "[co-author1] [co-author2] ...") czCmd.Flags().BoolP("git-push", "p", false, "Runs the git push command after the commit") + czCmd.Flags().StringP("git-push-flags", "f", "", "Passes the flags specified to the git push command") } diff --git a/src/cmd/root.go b/src/cmd/root.go index 631d37d..3737e60 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -56,6 +56,7 @@ var rootCmd = &cobra.Command{ vflag, _ := cmd.Flags().GetBool("version") gflag, _ := cmd.Flags().GetString("git") gpflag, _ := cmd.Flags().GetBool("git-push") + gpflagsflag, _ := cmd.Flags().GetString("git-push-flags") if vflag { fmt.Println("Cocommit version:", Coco_Version) @@ -109,13 +110,24 @@ var rootCmd = &cobra.Command{ return } - utils.GitWrapper(message, git_flags) + err := utils.GitWrapper(message, git_flags) + if err != nil { + fmt.Println("Error committing:", err) + } // prints the commit message to the console if the print flag is set if pflag { fmt.Println(message) } + var gp_flags []string + if gpflagsflag != "" { + gp_flags = strings.Split(gpflagsflag, " ") + } + if gpflag { - utils.GitPush() + err := utils.GitPush(gp_flags) + if err != nil { + fmt.Println("Error pushing to remote:", err) + } } }, } @@ -185,4 +197,5 @@ func init() { rootCmd.Flags().BoolP("version", "v", false, "Prints the version of the cocommit cli tool") rootCmd.Flags().StringP("git", "g", "", "Adds the given flags to the git command") rootCmd.Flags().BoolP("git-push", "p", false, "Runs git push after the commit") + rootCmd.Flags().StringP("git-push-flags", "f", "", "Adds the given flags to the git push command") }