2025-06-17 23:12:49 -04:00
|
|
|
/*
|
|
|
|
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",
|
2025-06-18 18:38:01 -04:00
|
|
|
Short: "Saves a new command to the database",
|
2025-06-17 23:12:49 -04:00
|
|
|
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)
|
|
|
|
cobra.CheckErr(err)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
CommandCmd.AddCommand(addCmd)
|
|
|
|
}
|