51 lines
913 B
Go
51 lines
913 B
Go
|
/*
|
||
|
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 server configuration",
|
||
|
// Long: `Saves server address, alias, port, and password.`,
|
||
|
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)
|
||
|
}
|