migrating to isSet and readme checks
This commit is contained in:
parent
35fb9fc270
commit
eaefba3292
@ -10,7 +10,7 @@ go install code.jakeyoungdev.com/jake/mctl@main #it is recommended to use a tagg
|
|||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
### Configuring mctl
|
### Configuring mctl
|
||||||
mctl requires a one-time setup via the 'config' command before interacting with any servers, password is entered securely from the terminal
|
mctl requires a one-time setup via the 'config' command before interacting with any servers, password is entered securely from the terminal and encrypted
|
||||||
```bash
|
```bash
|
||||||
mctl config -s <serveraddress> -p <rconport>
|
mctl config -s <serveraddress> -p <rconport>
|
||||||
```
|
```
|
||||||
@ -23,7 +23,7 @@ mctl login #makes auth request to server with saved password
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Sending commands
|
### Sending commands
|
||||||
If login is successful the app will enter the command loop, which allows commands to be sent directly to the server until 'mctl' is sent. Commands are sent as-is to the server, there is no validation of command syntax within mctl
|
If login is successful the app will enter the command loop, which allows commands to be sent directly to the server. Commands are sent as-is to the server, there is no validation of command syntax within mctl
|
||||||
```
|
```
|
||||||
Logging into X.X.X.X on port 61695
|
Logging into X.X.X.X on port 61695
|
||||||
Connected! Type 'mctl' to close
|
Connected! Type 'mctl' to close
|
||||||
@ -33,7 +33,7 @@ There are 0 of a max of 20 players online:
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Saving commands
|
### Saving commands
|
||||||
Commands can be saved under an alias for quick execution later, saved commands can contain placeholders '%s' that can be populated at runtime to allow for commands with unique runtime args to still be saved:
|
Commands can be saved under an alias for quick execution later, saved commands can contain placeholders '%s' that can be populated at runtime to allow for commands with unique runtime args to still be saved, see [example](#saving-and-running-example) for more:
|
||||||
```bash
|
```bash
|
||||||
mctl save <name>
|
mctl save <name>
|
||||||
```
|
```
|
||||||
@ -90,7 +90,7 @@ mctl delete <name>
|
|||||||
|server|s|yes|RCon address|
|
|server|s|yes|RCon address|
|
||||||
|
|
||||||
### Configuration file
|
### Configuration file
|
||||||
All configuration data will be kept in /home/.mctl.yaml or C:\\Users\\username\\.mctl.yaml, passwords are encrypted for an added layer of security
|
All configuration data will be kept in the home directory and any sensitive data is encrypted for added security
|
||||||
|
|
||||||
## Security
|
## Security
|
||||||
RCon is an inherently insecure protocol, passwords are sent in plaintext and, if possible, the port should not be exposed to the internet. It is best to keep these connections local or over a VPN
|
RCon is an inherently insecure protocol, passwords are sent in plaintext and, if possible, the port should not be exposed to the internet. It is best to keep these connections local or over a VPN
|
||||||
|
@ -17,16 +17,12 @@ var deleteCmd = &cobra.Command{
|
|||||||
Short: "Delete a saved command",
|
Short: "Delete a saved command",
|
||||||
Long: `Deletes a command stored using the save command`,
|
Long: `Deletes a command stored using the save command`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var cm map[string]any
|
if viper.IsSet("customcmd") {
|
||||||
cmdMap := viper.Get("customcmd")
|
cmdMap := viper.Get("customcmd").(map[string]any)
|
||||||
if cmdMap == nil {
|
delete(cmdMap, args[0])
|
||||||
cm = make(map[string]any, 0)
|
viper.Set("customcmd", cmdMap)
|
||||||
} else {
|
viper.WriteConfig()
|
||||||
cm = cmdMap.(map[string]any)
|
|
||||||
}
|
}
|
||||||
delete(cm, args[0])
|
|
||||||
viper.Set("customcmd", cmdMap)
|
|
||||||
viper.WriteConfig()
|
|
||||||
},
|
},
|
||||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
|
@ -58,9 +58,10 @@ var loginCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
//ensure config command has been run
|
//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 errors.New("the 'config' command must be run before you can interact with servers")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
17
cmd/run.go
17
cmd/run.go
@ -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
|
Long: `Loads a saved command, injects the supplied arguments into the command, and sends the command to the remove server
|
||||||
printing the response`,
|
printing the response`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
//check for command map
|
cm := viper.Get("customcmd").(map[string]any)
|
||||||
var cm map[string]any
|
|
||||||
cmdMap := viper.Get("customcmd")
|
|
||||||
if cmdMap == nil {
|
|
||||||
cm = make(map[string]any, 0)
|
|
||||||
} else {
|
|
||||||
cm = cmdMap.(map[string]any)
|
|
||||||
}
|
|
||||||
//is this an existing command
|
//is this an existing command
|
||||||
cmdRun, ok := cm[args[0]]
|
cmdRun, ok := cm[args[0]]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -58,11 +51,15 @@ var runCmd = &cobra.Command{
|
|||||||
fmt.Println(res)
|
fmt.Println(res)
|
||||||
},
|
},
|
||||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
//ensure configuration has been setup
|
//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 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
|
//ensure we have a command name
|
||||||
al := len(args)
|
al := len(args)
|
||||||
if al == 0 {
|
if al == 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user