2025-04-17 21:25:54 +00:00
|
|
|
/*
|
|
|
|
Copyright © 2025 Jake jake.young.dev@gmail.com
|
|
|
|
*/
|
2025-06-17 23:12:49 -04:00
|
|
|
package command
|
2025-04-17 21:25:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2025-06-16 19:17:52 -04:00
|
|
|
"fmt"
|
2025-04-17 21:25:54 +00:00
|
|
|
|
2025-06-16 19:17:52 -04:00
|
|
|
"code.jakeyoungdev.com/jake/mctl/database"
|
2025-04-17 21:25:54 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var deleteCmd = &cobra.Command{
|
2025-06-17 23:12:49 -04:00
|
|
|
Use: "delete",
|
|
|
|
Example: "mctl command delete <name>",
|
2025-06-18 18:38:01 -04:00
|
|
|
Short: "Deletes a command from the database",
|
2025-04-17 21:25:54 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2025-06-16 19:17:52 -04:00
|
|
|
db, err := database.New()
|
|
|
|
cobra.CheckErr(err)
|
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
err = db.DeleteCmd(args[0])
|
|
|
|
cobra.CheckErr(err)
|
2025-06-17 23:12:49 -04:00
|
|
|
|
|
|
|
fmt.Println("Command deleted!")
|
2025-04-17 21:25:54 +00:00
|
|
|
},
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
if len(args) == 0 {
|
2025-06-17 23:12:49 -04:00
|
|
|
return errors.New("name parameter missing")
|
2025-04-17 21:25:54 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2025-06-17 23:12:49 -04:00
|
|
|
CommandCmd.AddCommand(deleteCmd)
|
2025-04-17 21:25:54 +00:00
|
|
|
}
|