68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
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
|
|
}
|