mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
Merge pull request #43 from Slug-Boi/feat_pass_git_flags
This commit is contained in:
@@ -157,4 +157,35 @@ func Test_CommitCmdWithM(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// output doesnt match the expected terminal behavior very confusing...
|
||||||
|
// func Test_CommitWithGitFlags(t *testing.T) {
|
||||||
|
// skipCI(t)
|
||||||
|
// setup()
|
||||||
|
// defer teardown()
|
||||||
|
//
|
||||||
|
// //stdout reader
|
||||||
|
// outC, r, w, old := StdoutReader()
|
||||||
|
//
|
||||||
|
// go func() {
|
||||||
|
// var buf bytes.Buffer
|
||||||
|
// io.Copy(&buf, r)
|
||||||
|
// outC <- buf.String()
|
||||||
|
// }()
|
||||||
|
//
|
||||||
|
// cmd := rootCmd
|
||||||
|
// cmd.SetArgs([]string{"-g", "\"-a --dry-run\"", "Test commit message"})
|
||||||
|
// cmd.Execute()
|
||||||
|
//
|
||||||
|
// w.Close()
|
||||||
|
// os.Stdout = old
|
||||||
|
// outStr := <-outC
|
||||||
|
// if outStr == "" {
|
||||||
|
// t.Errorf("Expected output but got nothing")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if !strings.Contains(outStr, "Changes to be commited:\n") {
|
||||||
|
// t.Errorf("Expected to find 'Test commit message' in output but got %s", outStr)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// root CMD TEST END
|
// root CMD TEST END
|
||||||
|
|||||||
+8
-1
@@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Slug-Boi/cocommit/src/cmd/tui"
|
"github.com/Slug-Boi/cocommit/src/cmd/tui"
|
||||||
"github.com/Slug-Boi/cocommit/src/cmd/utils"
|
"github.com/Slug-Boi/cocommit/src/cmd/utils"
|
||||||
@@ -24,6 +25,7 @@ This will require the user to have commitizen installed on their system.`,
|
|||||||
// check if the print flag is set
|
// check if the print flag is set
|
||||||
pflag, _ := cmd.Flags().GetBool("print")
|
pflag, _ := cmd.Flags().GetBool("print")
|
||||||
cflag, _ := cmd.Flags().GetBool("cli")
|
cflag, _ := cmd.Flags().GetBool("cli")
|
||||||
|
gflag, _ := cmd.Flags().GetString("git")
|
||||||
|
|
||||||
// run execute commands again as root run will not call this part
|
// run execute commands again as root run will not call this part
|
||||||
message = utils.Cz_Call()
|
message = utils.Cz_Call()
|
||||||
@@ -46,7 +48,11 @@ This will require the user to have commitizen installed on their system.`,
|
|||||||
message = utils.Commit(message, authors)
|
message = utils.Commit(message, authors)
|
||||||
|
|
||||||
// commit the message
|
// commit the message
|
||||||
utils.GitWrapper(message)
|
var git_flags []string
|
||||||
|
if gflag != "" {
|
||||||
|
git_flags = strings.Split(gflag, " ")
|
||||||
|
}
|
||||||
|
utils.GitWrapper(message, git_flags)
|
||||||
|
|
||||||
if pflag {
|
if pflag {
|
||||||
fmt.Println(message)
|
fmt.Println(message)
|
||||||
@@ -56,6 +62,7 @@ This will require the user to have commitizen installed on their system.`,
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(czCmd)
|
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", "p", false, "Print the commit message")
|
||||||
czCmd.Flags().BoolP("cli", "c", false, "[co-author1] [co-author2] ...")
|
czCmd.Flags().BoolP("cli", "c", false, "[co-author1] [co-author2] ...")
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-3
@@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Slug-Boi/cocommit/src/cmd/tui"
|
"github.com/Slug-Boi/cocommit/src/cmd/tui"
|
||||||
"github.com/Slug-Boi/cocommit/src/cmd/utils"
|
"github.com/Slug-Boi/cocommit/src/cmd/utils"
|
||||||
@@ -33,6 +34,13 @@ var rootCmd = &cobra.Command{
|
|||||||
pflag, _ := cmd.Flags().GetBool("print")
|
pflag, _ := cmd.Flags().GetBool("print")
|
||||||
tflag, _ := cmd.Flags().GetBool("test_print")
|
tflag, _ := cmd.Flags().GetBool("test_print")
|
||||||
aflag, _ := cmd.Flags().GetBool("authors")
|
aflag, _ := cmd.Flags().GetBool("authors")
|
||||||
|
gflag, _ := cmd.Flags().GetString("git")
|
||||||
|
|
||||||
|
var git_flags []string
|
||||||
|
// runs the git commit command
|
||||||
|
if gflag != "" {
|
||||||
|
git_flags = strings.Split(gflag, " ")
|
||||||
|
}
|
||||||
|
|
||||||
if aflag {
|
if aflag {
|
||||||
tui.Entry()
|
tui.Entry()
|
||||||
@@ -61,7 +69,7 @@ var rootCmd = &cobra.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.GitWrapper(args[0])
|
utils.GitWrapper(args[0], git_flags)
|
||||||
if pflag {
|
if pflag {
|
||||||
fmt.Println(args[0])
|
fmt.Println(args[0])
|
||||||
}
|
}
|
||||||
@@ -79,12 +87,17 @@ var rootCmd = &cobra.Command{
|
|||||||
message = utils.Commit(args[0], args[1:])
|
message = utils.Commit(args[0], args[1:])
|
||||||
|
|
||||||
tui:
|
tui:
|
||||||
|
if tflag {
|
||||||
|
fmt.Println(message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// prints the commit message to the console if the print flag is set
|
// prints the commit message to the console if the print flag is set
|
||||||
if pflag {
|
if pflag {
|
||||||
fmt.Println(message)
|
fmt.Println(message)
|
||||||
}
|
}
|
||||||
// runs the git commit command
|
|
||||||
utils.GitWrapper(message)
|
utils.GitWrapper(message, git_flags)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,4 +121,5 @@ func init() {
|
|||||||
rootCmd.Flags().BoolP("test_print", "t", false, "Prints the commit message to the console without running the git commit command")
|
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("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("authors", "a", false, "Runs the author list TUI")
|
||||||
|
rootCmd.Flags().StringP("git", "g", "", "Adds the given flags to the git command")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,9 +61,15 @@ skip_loop:
|
|||||||
return sb.String()
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GitWrapper(commit string) {
|
func GitWrapper(commit string, flags []string) {
|
||||||
// commit shell command
|
// commit shell command
|
||||||
cmd := exec.Command("git", "commit", "-m", commit)
|
// specify git command
|
||||||
|
input := []string{"commit"}
|
||||||
|
// append the message to the flags
|
||||||
|
flags = append(flags, "-m", commit)
|
||||||
|
// concat the git command and the flags + message
|
||||||
|
input = append(input, flags...)
|
||||||
|
cmd := exec.Command("git", input...)
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/18159704/how-to-debug-exit-status-1-error-when-running-exec-command-in-golang
|
// https://stackoverflow.com/questions/18159704/how-to-debug-exit-status-1-error-when-running-exec-command-in-golang
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user