mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
feat: add git push flag to commands
This commit is contained in:
+8
-2
@@ -23,9 +23,10 @@ This will require the user to have commitizen installed on their system.`,
|
||||
var authors []string
|
||||
|
||||
// check if the print flag is set
|
||||
pflag, _ := cmd.Flags().GetBool("print")
|
||||
pflag, _ := cmd.Flags().GetBool("print-output")
|
||||
cflag, _ := cmd.Flags().GetBool("cli")
|
||||
gflag, _ := cmd.Flags().GetString("git")
|
||||
gpflag, _ := cmd.Flags().GetBool("git-push")
|
||||
|
||||
// run execute commands again as root run will not call this part
|
||||
message = utils.Cz_Call()
|
||||
@@ -57,12 +58,17 @@ This will require the user to have commitizen installed on their system.`,
|
||||
if pflag {
|
||||
fmt.Println(message)
|
||||
}
|
||||
|
||||
if gpflag {
|
||||
utils.GitPush()
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(czCmd)
|
||||
czCmd.Flags().StringP("git", "g", "", "Passes the flags specified to the git command")
|
||||
czCmd.Flags().BoolP("print", "p", false, "Print the commit message")
|
||||
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")
|
||||
}
|
||||
|
||||
+14
-6
@@ -34,16 +34,17 @@ var rootCmd = &cobra.Command{
|
||||
var message string
|
||||
|
||||
// check if the print flag is set
|
||||
pflag, _ := cmd.Flags().GetBool("print")
|
||||
pflag, _ := cmd.Flags().GetBool("print-output")
|
||||
tflag, _ := cmd.Flags().GetBool("test_print")
|
||||
aflag, _ := cmd.Flags().GetBool("authors")
|
||||
vflag, _ := cmd.Flags().GetBool("version")
|
||||
gflag, _ := cmd.Flags().GetString("git")
|
||||
gflag, _ := cmd.Flags().GetString("git")
|
||||
gpflag, _ := cmd.Flags().GetBool("git-push")
|
||||
|
||||
if vflag {
|
||||
fmt.Println("Cocommit version:", Coco_Version)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
var git_flags []string
|
||||
// runs the git commit command
|
||||
@@ -82,6 +83,10 @@ var rootCmd = &cobra.Command{
|
||||
if pflag {
|
||||
fmt.Println(args[0])
|
||||
}
|
||||
|
||||
if gpflag {
|
||||
utils.GitPush()
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
@@ -101,12 +106,14 @@ var rootCmd = &cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
utils.GitWrapper(message, git_flags)
|
||||
// prints the commit message to the console if the print flag is set
|
||||
if pflag {
|
||||
fmt.Println(message)
|
||||
}
|
||||
|
||||
utils.GitWrapper(message, git_flags)
|
||||
if gpflag {
|
||||
utils.GitPush()
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -126,10 +133,11 @@ func Execute() {
|
||||
|
||||
func init() {
|
||||
//rootCmD := RootCmd()
|
||||
rootCmd.Flags().BoolP("print", "p", false, "Prints the commit message to the console")
|
||||
rootCmd.Flags().BoolP("print-output", "o", false, "Prints the commit message to the console")
|
||||
rootCmd.Flags().BoolP("test_print", "t", false, "Prints the commit message to the console without running the git commit command")
|
||||
rootCmd.Flags().BoolP("message", "m", false, "Does nothing but allows for -m to be used in the command")
|
||||
rootCmd.Flags().BoolP("authors", "a", false, "Runs the author list TUI")
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -82,6 +82,18 @@ func GitWrapper(commit string, flags []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func GitPush() {
|
||||
cmd := exec.Command("git", "push")
|
||||
|
||||
cmd_output, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
println(fmt.Sprint(err) + " : " + string(cmd_output))
|
||||
} else {
|
||||
println(string(cmd_output))
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to add an author to the commit message
|
||||
func sb_author(committer string) {
|
||||
sb.WriteString("\nCo-authored-by: ")
|
||||
|
||||
Reference in New Issue
Block a user