41 lines
807 B
Go
41 lines
807 B
Go
/*
|
|
Copyright © 2025 Jake jake.young.dev@gmail.com
|
|
*/
|
|
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"code.jakeyoungdev.com/jake/mctl/database"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// deleteCmd represents the delete command
|
|
var deleteCmd = &cobra.Command{
|
|
Use: "delete <name>",
|
|
Example: "mctl delete newcmd",
|
|
Short: "Delete a saved command",
|
|
Long: `Deletes a command stored using the save command`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
db, err := database.New()
|
|
cobra.CheckErr(err)
|
|
defer db.Close()
|
|
|
|
err = db.DeleteCmd(args[0])
|
|
cobra.CheckErr(err)
|
|
fmt.Println("Command deleted")
|
|
},
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
|
if len(args) == 0 {
|
|
return errors.New("name argument is required")
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(deleteCmd)
|
|
}
|