36 lines
693 B
Go
36 lines
693 B
Go
|
/*
|
||
|
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)
|
||
|
}
|