- readme updates - delete command added - commands now saved in a map vs fields - login and run now ensure config has been run to prevent errors
43 lines
863 B
Go
43 lines
863 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) {
|
|
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)
|
|
}
|