dev/standards (#4)

Reviewed-on: #4
Co-authored-by: jake <jake.young.dev@gmail.com>
Co-committed-by: jake <jake.young.dev@gmail.com>
This commit is contained in:
2025-04-19 05:13:53 +00:00
committed by jake
parent 35fb9fc270
commit a3527d3388
5 changed files with 19 additions and 25 deletions

View File

@@ -17,16 +17,12 @@ var deleteCmd = &cobra.Command{
Short: "Delete a saved command",
Long: `Deletes a command stored using the save command`,
Run: func(cmd *cobra.Command, args []string) {
var cm map[string]any
cmdMap := viper.Get("customcmd")
if cmdMap == nil {
cm = make(map[string]any, 0)
} else {
cm = cmdMap.(map[string]any)
if viper.IsSet("customcmd") {
cmdMap := viper.Get("customcmd").(map[string]any)
delete(cmdMap, args[0])
viper.Set("customcmd", cmdMap)
viper.WriteConfig()
}
delete(cm, args[0])
viper.Set("customcmd", cmdMap)
viper.WriteConfig()
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {

View File

@@ -58,9 +58,10 @@ var loginCmd = &cobra.Command{
},
PreRunE: func(cmd *cobra.Command, args []string) error {
//ensure config command has been run
if viper.Get("server") == "" || viper.Get("password") == "" || viper.Get("port") == 0 {
if !viper.IsSet("server") || !viper.IsSet("password") || !viper.IsSet("port") {
return errors.New("the 'config' command must be run before you can interact with servers")
}
return nil
},
}

View File

@@ -14,7 +14,7 @@ var rootCmd = &cobra.Command{
Use: "mctl",
Short: "A remote console client",
Long: `mctl is a terminal-friendly remote console client made to manage game servers.`,
Version: "v0.3.2",
Version: "v0.3.3",
// Run: func(cmd *cobra.Command, args []string) { },
}

View File

@@ -22,14 +22,7 @@ var runCmd = &cobra.Command{
Long: `Loads a saved command, injects the supplied arguments into the command, and sends the command to the remove server
printing the response`,
Run: func(cmd *cobra.Command, args []string) {
//check for command map
var cm map[string]any
cmdMap := viper.Get("customcmd")
if cmdMap == nil {
cm = make(map[string]any, 0)
} else {
cm = cmdMap.(map[string]any)
}
cm := viper.Get("customcmd").(map[string]any)
//is this an existing command
cmdRun, ok := cm[args[0]]
if !ok {
@@ -58,11 +51,15 @@ var runCmd = &cobra.Command{
fmt.Println(res)
},
PreRunE: func(cmd *cobra.Command, args []string) error {
//ensure configuration has been setup
if viper.Get("server") == "" || viper.Get("password") == "" || viper.Get("port") == 0 {
//ensure config command has been run
if !viper.IsSet("server") || !viper.IsSet("password") || !viper.IsSet("port") {
return errors.New("the 'config' command must be run before you can interact with servers")
}
if !viper.IsSet("customcmd") {
return errors.New("no saved commands to run")
}
//ensure we have a command name
al := len(args)
if al == 0 {