mctl/cmd/server/active.go
jake 7ff43c82c2 [fix] Testing fixes
- sqlite error handling and wrapping
- more responsive commands
- database updates
2025-06-19 17:23:17 -04:00

44 lines
847 B
Go

/*
Copyright © 2025 Jake jake.young.dev@gmail.com
*/
package server
import (
"errors"
"fmt"
"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",
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
db, err := database.New()
cobra.CheckErr(err)
defer db.Close()
err = db.SetActiveServer(args[0])
if err.Error() == ErrInit {
fmt.Println(ErrInitRsp)
return
}
cobra.CheckErr(err)
fmt.Println("Active server updated")
},
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)
}