43 lines
859 B
Go
43 lines
859 B
Go
|
/*
|
||
|
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
|
||
|
*/
|
||
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
|
||
|
"github.com/spf13/cobra"
|
||
|
"github.com/spf13/viper"
|
||
|
)
|
||
|
|
||
|
// 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) {
|
||
|
var cm map[string]any
|
||
|
cmdMap := viper.Get("customcmd")
|
||
|
if cmdMap == nil {
|
||
|
cm = make(map[string]any, 0)
|
||
|
} else {
|
||
|
cm = cmdMap.(map[string]any)
|
||
|
}
|
||
|
delete(cm, args[0])
|
||
|
viper.Set("customcmd", cmdMap)
|
||
|
viper.WriteConfig()
|
||
|
},
|
||
|
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)
|
||
|
}
|