diff --git a/cmd/activate_commit_validator.go b/cmd/activate_commit_validator.go new file mode 100644 index 0000000..ad7d3b4 --- /dev/null +++ b/cmd/activate_commit_validator.go @@ -0,0 +1,32 @@ +// Copyright 2022 Paulus Gandung Prakosa +// All rights reserved. + +package cmd + +import ( + "github.com/plvhx/polar/src" + "github.com/spf13/cobra" +) + +var ( + hookName = "prepare-commit-msg" + hookCommand = "polar validate-commit" +) + +var activateFunc = func(cmd *cobra.Command, args []string) { + if err := src.CreateHook(hookName, hookCommand); err != nil { + panic(err) + } +} + +var activateCmd = &cobra.Command{ + Use: "activate-commit-validator", + Short: "Activate prepare-commit-msg hook", + Long: "Activate prepare-commit-msg hook for validating commit message.", + Example: "polar activate-commit-validator", + Run: activateFunc, +} + +func init() { + rootCmd.AddCommand(activateCmd) +}