lots o progress
- added 'command' subcommand - removed viper - setup commands added - still a WIP - readme TODO update
This commit is contained in:
50
cmd/command/add.go
Normal file
50
cmd/command/add.go
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user