Files
mctl/cmd/command/delete.go
jake b41b5e2be8
All checks were successful
code scans / scans (push) Successful in 26s
code scans / scans (pull_request) Successful in 24s
moving run command
- run command is no longer attached to the 'command' subcmd
- run is standalone
2025-11-26 13:04:14 -05:00

47 lines
919 B
Go

/*
Copyright © 2025 Jake jake.young.dev@gmail.com
*/
package command
import (
"errors"
"fmt"
"code.jakeyoungdev.com/jake/mctl/constants"
"code.jakeyoungdev.com/jake/mctl/database"
"github.com/spf13/cobra"
)
var deleteCmd = &cobra.Command{
Use: "delete",
Example: "mctl command delete <name>",
Short: "Deletes a command from the database",
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
db, err := database.New()
cobra.CheckErr(err)
defer db.Close()
err = db.DeleteCmd(args[0])
if err != nil {
if err.Error() == constants.ErrInit {
fmt.Println(constants.ErrInitRsp)
return
}
}
cobra.CheckErr(err)
fmt.Println("Command deleted")
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("name parameter missing")
}
return nil
},
}
func init() {
CommandCmd.AddCommand(deleteCmd)
}