2025-04-17 21:25:54 +00:00
|
|
|
/*
|
|
|
|
Copyright © 2025 Jake jake.young.dev@gmail.com
|
|
|
|
*/
|
|
|
|
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) {
|
2025-04-19 05:13:53 +00:00
|
|
|
if viper.IsSet("customcmd") {
|
|
|
|
cmdMap := viper.Get("customcmd").(map[string]any)
|
|
|
|
delete(cmdMap, args[0])
|
|
|
|
viper.Set("customcmd", cmdMap)
|
2025-04-24 18:22:16 +00:00
|
|
|
err := viper.WriteConfig()
|
|
|
|
cobra.CheckErr(err)
|
2025-04-17 21:25:54 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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)
|
|
|
|
}
|