All checks were successful
code scans / scans (push) Successful in 1m27s
Reviewed-on: #6 Co-authored-by: jake <jake.young.dev@gmail.com> Co-committed-by: jake <jake.young.dev@gmail.com>
40 lines
830 B
Go
40 lines
830 B
Go
/*
|
|
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) {
|
|
if viper.IsSet("customcmd") {
|
|
cmdMap := viper.Get("customcmd").(map[string]any)
|
|
delete(cmdMap, args[0])
|
|
viper.Set("customcmd", cmdMap)
|
|
err := viper.WriteConfig()
|
|
cobra.CheckErr(err)
|
|
}
|
|
},
|
|
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)
|
|
}
|