finishing sqlite changes
- finished default/active server logic - dev done - needs testing
This commit is contained in:
35
cmd/server/active.go
Normal file
35
cmd/server/active.go
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright © 2025 Jake jake.young.dev@gmail.com
|
||||
*/
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"code.jakeyoungdev.com/jake/mctl/database"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var activeCmd = &cobra.Command{
|
||||
Use: "active",
|
||||
Example: "mctl server active <server>",
|
||||
Short: "sets the active server to run commands on",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
db, err := database.New()
|
||||
cobra.CheckErr(err)
|
||||
defer db.Close()
|
||||
|
||||
err = db.SetActiveServer(args[0])
|
||||
cobra.CheckErr(err)
|
||||
},
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New("server parameter missing")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
ServerCmd.AddCommand(activeCmd)
|
||||
}
|
@@ -20,7 +20,7 @@ var addCmd = &cobra.Command{
|
||||
Use: "add",
|
||||
Example: "mctl server add",
|
||||
Short: "Saves a new server configuration",
|
||||
Long: `Saves server address, alias, port, and password.`,
|
||||
Long: `Saves server address, alias, port, and password to the database.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
|
||||
|
@@ -13,8 +13,7 @@ import (
|
||||
var deleteCmd = &cobra.Command{
|
||||
Use: "delete",
|
||||
Example: "mctl server delete <server>",
|
||||
// Short: "Deletes a server",
|
||||
// Long: `Deletes server configuration`,
|
||||
Short: "deletes a server from the database",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
db, err := database.New()
|
||||
cobra.CheckErr(err)
|
||||
|
@@ -10,12 +10,6 @@ import (
|
||||
var ServerCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
Example: "mctl server <subcommand>",
|
||||
// Short: "A remote console client",
|
||||
// Long: `mctl is a terminal-friendly remote console client made to manage game servers.`,
|
||||
// Version: "v0.3.4",
|
||||
// Run: func(cmd *cobra.Command, args []string) { },
|
||||
}
|
||||
|
||||
func init() {
|
||||
// rootCmd.AddCommand()
|
||||
}
|
||||
func init() {}
|
||||
|
@@ -17,8 +17,7 @@ import (
|
||||
var updateCmd = &cobra.Command{
|
||||
Use: "update",
|
||||
Example: "mctl server update <name>",
|
||||
// Short: "Saves a new server configuration",
|
||||
// Long: `Saves server address, alias, port, and password.`,
|
||||
Short: "updates a saved servers password in the database",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
//read in password using term to keep it secure/hidden from bash history
|
||||
fmt.Printf("Password: ")
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
var viewCmd = &cobra.Command{
|
||||
Use: "view",
|
||||
Example: "mctl server view",
|
||||
Short: "view all servers",
|
||||
Short: "view all saved servers",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
db, err := database.New()
|
||||
cobra.CheckErr(err)
|
||||
@@ -27,7 +27,8 @@ var viewCmd = &cobra.Command{
|
||||
fmt.Printf("Name: %s\n", s.Name)
|
||||
fmt.Printf("Address: %s\n", s.Server)
|
||||
fmt.Printf("Port: %d\n", s.Port)
|
||||
fmt.Printf("Password: %s\n", s.Password)
|
||||
fmt.Println("Password: [REDACTED]")
|
||||
fmt.Printf("Default: %t\n", s.Default)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user