mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 20:55:47 +00:00
feat: added commitizen support (due to cmd execution styles this will not be in the test suite)
Due to the way that the interactive cli call has to be made there is no good way to automate the tests for it without spending a long time trying to understand go pipes. since this is more of an extra feature anyways I am fine with leaving this somewhat untested especially since it is small isolated code
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/tui"
|
||||
"github.com/Slug-Boi/cocommit/src_code/go_src/cmd/utils"
|
||||
"github.com/inancgumus/screen"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// czCmd represents the cz command
|
||||
var czCmd = &cobra.Command{
|
||||
Use: "cz",
|
||||
Short: "Allows for commitizen commit messages",
|
||||
Long: `This command will allow the user to use commitizen to craft the commit message
|
||||
after which the user will be able to add co-authors to the commit message. This will require
|
||||
the user to have commitizen installed on their system.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var message string
|
||||
var authors []string
|
||||
|
||||
// check if the print flag is set
|
||||
pflag, _ := cmd.Flags().GetBool("print")
|
||||
cflag, _ := cmd.Flags().GetBool("cli")
|
||||
|
||||
// run execute commands again as root run will not call this part
|
||||
message = utils.Cz_Call()
|
||||
|
||||
if cflag {
|
||||
// call the cli style syntax
|
||||
authors = args
|
||||
goto skip_tui
|
||||
}
|
||||
|
||||
// for good measure clear the screen
|
||||
screen.Clear()
|
||||
screen.MoveTopLeft()
|
||||
|
||||
// call tui
|
||||
authors = tui.Entry()
|
||||
|
||||
skip_tui:
|
||||
// build the commit message
|
||||
message = utils.Commit(message, authors)
|
||||
|
||||
// commit the message
|
||||
utils.GitWrapper(message)
|
||||
|
||||
if pflag {
|
||||
fmt.Println(message)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(czCmd)
|
||||
czCmd.Flags().BoolP("print", "p", false, "Print the commit message")
|
||||
czCmd.Flags().BoolP("cli", "c", false, "Use the cli style syntax to add co-authors")
|
||||
}
|
||||
Reference in New Issue
Block a user