feat: migrate to golang
This commit is contained in:
67
internal/cli/hook.go
Normal file
67
internal/cli/hook.go
Normal file
@ -0,0 +1,67 @@
|
||||
package cli
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
func newHookCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "hook",
|
||||
Short: "Manage hook scripts",
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
&cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initialize hooks directory with template scripts",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
m, err := newManagers("", "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Hook.Init()
|
||||
return nil
|
||||
},
|
||||
},
|
||||
&cobra.Command{
|
||||
Use: "list",
|
||||
Short: "Show hooks directory location and list scripts",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
m, err := newManagers("", "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Hook.ListHooks()
|
||||
return nil
|
||||
},
|
||||
},
|
||||
&cobra.Command{
|
||||
Use: "edit <script>",
|
||||
Short: "Edit a hook script",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
m, err := newManagers("", "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Hook.Edit(args[0])
|
||||
return nil
|
||||
},
|
||||
},
|
||||
&cobra.Command{
|
||||
Use: "rm <script>",
|
||||
Short: "Remove a hook script",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
m, err := newManagers("", "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Hook.Rm(args[0])
|
||||
return nil
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user