lots o progress

- added 'command' subcommand
- removed viper
- setup commands added
- still a WIP
- readme TODO update
This commit is contained in:
2025-06-17 23:12:49 -04:00
parent 77bb3166c4
commit fe37cac2da
25 changed files with 456 additions and 488 deletions

48
cmd/server/update.go Normal file
View File

@@ -0,0 +1,48 @@
/*
Copyright © 2025 Jake jake.young.dev@gmail.com
*/
package server
import (
"encoding/base64"
"errors"
"fmt"
"os"
"code.jakeyoungdev.com/jake/mctl/database"
"github.com/spf13/cobra"
"golang.org/x/term"
)
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.`,
Run: func(cmd *cobra.Command, args []string) {
//read in password using term to keep it secure/hidden from bash history
fmt.Printf("Password: ")
ps, err := term.ReadPassword(int(os.Stdin.Fd()))
cobra.CheckErr(err)
db, err := database.New()
cobra.CheckErr(err)
defer db.Close()
err = db.UpdateServer(args[0], base64.StdEncoding.EncodeToString(ps))
cobra.CheckErr(err)
fmt.Printf("%s password updated!", args[0])
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("name command required")
}
return nil
},
}
func init() {
ServerCmd.AddCommand(updateCmd)
}