/* Copyright © 2025 Jake jake.young.dev@gmail.com */ package command import ( "bufio" "fmt" "os" "code.jakeyoungdev.com/jake/mctl/database" "github.com/spf13/cobra" ) var addCmd = &cobra.Command{ Use: "add", Example: "mctl command add", Short: "Saves a new command to the database", SilenceUsage: true, Run: func(cmd *cobra.Command, args []string) { scanner := bufio.NewScanner(os.Stdin) //get server information var cfgname string fmt.Printf("Command alias: ") if scanner.Scan() { cfgname = scanner.Text() } var cfgcmd string fmt.Printf("Command: ") if scanner.Scan() { cfgcmd = scanner.Text() } db, err := database.New() cobra.CheckErr(err) defer db.Close() err = db.Init() cobra.CheckErr(err) err = db.SaveCmd(cfgname, cfgcmd) if err != nil { if err.Error() == ErrInit { fmt.Println(ErrInitRsp) return } } cobra.CheckErr(err) fmt.Println("Command saved") }, } func init() { CommandCmd.AddCommand(addCmd) }