new/clear-command (#8)
Reviewed-on: #8 Co-authored-by: jake <jake.young.dev@gmail.com> Co-committed-by: jake <jake.young.dev@gmail.com>
This commit is contained in:
parent
386a766185
commit
f8282c3676
@ -1,5 +1,5 @@
|
|||||||
name: "code scans"
|
name: "code scans"
|
||||||
on: [push, pull_request] #runs on pushes to any branch
|
on: pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
scans:
|
scans:
|
||||||
|
18
README.md
18
README.md
@ -1,12 +1,18 @@
|
|||||||
# mctl
|
# mctl
|
||||||
mctl is a terminal-friendly remote console client
|
mctl is a terminal-friendly remote console client
|
||||||
|
|
||||||
|
## Index
|
||||||
|
1. [Installation](#installation)
|
||||||
|
2. [Setup](#setup)
|
||||||
|
3. [Documentation](#documentation)
|
||||||
|
4. [Security](#security)
|
||||||
|
5. [Development](#development)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
Install mctl using golang
|
Install mctl using golang
|
||||||
```bash
|
```bash
|
||||||
go install code.jakeyoungdev.com/jake/mctl@main #it is recommended to use a tagged version
|
go install code.jakeyoungdev.com/jake/mctl@main #it is recommended to use a tagged version
|
||||||
```
|
```
|
||||||
<br />
|
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
### Configuring mctl
|
### Configuring mctl
|
||||||
@ -75,6 +81,13 @@ Commands can be deleted with:
|
|||||||
mctl delete <name>
|
mctl delete <name>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Clear configuration file
|
||||||
|
To clear all fields from the configuration file use:
|
||||||
|
```bash
|
||||||
|
#CAUTION: If the config file is cleared all data previously saved will be lost forever
|
||||||
|
mctl clear
|
||||||
|
```
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
### Commands
|
### Commands
|
||||||
|Command|Description|
|
|Command|Description|
|
||||||
@ -85,6 +98,7 @@ mctl delete <name>
|
|||||||
|view \<name>|displays saved command|
|
|view \<name>|displays saved command|
|
||||||
|delete \<name>|deletes saved command|
|
|delete \<name>|deletes saved command|
|
||||||
|run \<name> args...|runs saved command filling placeholders with supplied args|
|
|run \<name> args...|runs saved command filling placeholders with supplied args|
|
||||||
|
|clear|clears config file|
|
||||||
|
|
||||||
### Flags
|
### Flags
|
||||||
#### config
|
#### config
|
||||||
@ -102,4 +116,4 @@ RCon is an inherently insecure protocol, passwords are sent in plaintext and, if
|
|||||||
mctl utilizes [govulncheck](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck) and [gosec](https://github.com/securego/gosec) in workflows to ensure quality, secure code is being pushed. These workflow steps must pass before a PR will be accepted
|
mctl utilizes [govulncheck](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck) and [gosec](https://github.com/securego/gosec) in workflows to ensure quality, secure code is being pushed. These workflow steps must pass before a PR will be accepted
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
this repo is currently in heavy development and may encounter breaking changes, use a tag to prevent any surprises
|
this repo is currently in development and may encounter breaking changes, use a tag to prevent any surprises
|
43
cmd/clear.go
Normal file
43
cmd/clear.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2025 Jake jake.young.dev@gmail.com
|
||||||
|
*/
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"code.jakeyoungdev.com/jake/mctl/models"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
// clearCmd represents the clear command
|
||||||
|
var clearCmd = &cobra.Command{
|
||||||
|
Use: "clear",
|
||||||
|
Short: "Clear config file",
|
||||||
|
Long: `Clears all configuration values for mctl, all server configuration will be lost`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
home, err := os.UserHomeDir()
|
||||||
|
cobra.CheckErr(err)
|
||||||
|
|
||||||
|
viper.AddConfigPath(home)
|
||||||
|
viper.SetConfigType("yaml")
|
||||||
|
viper.SetConfigName(".mctl")
|
||||||
|
|
||||||
|
err = viper.ReadInConfig()
|
||||||
|
if err == nil {
|
||||||
|
//clear values if file exists
|
||||||
|
for _, v := range models.ConfigFields {
|
||||||
|
viper.Set(v, "")
|
||||||
|
}
|
||||||
|
err := viper.WriteConfig()
|
||||||
|
cobra.CheckErr(err)
|
||||||
|
fmt.Println("Config file cleared, use 'config' command to re-populate it")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(clearCmd)
|
||||||
|
}
|
@ -76,9 +76,8 @@ func initConfig() {
|
|||||||
viper.SetConfigName(".mctl")
|
viper.SetConfigName(".mctl")
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
err = viper.ReadInConfig()
|
err = viper.ReadInConfig()
|
||||||
cobra.CheckErr(err)
|
|
||||||
|
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
if err != nil {
|
||||||
//file does not exist, create it
|
//file does not exist, create it
|
||||||
viper.Set("server", cfgserver)
|
viper.Set("server", cfgserver)
|
||||||
viper.Set("password", "")
|
viper.Set("password", "")
|
||||||
|
4
models/data.go
Normal file
4
models/data.go
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
//list of all fields kept in config file
|
||||||
|
var ConfigFields = [6]string{"customcmd", "device", "nonce", "port", "server", "password"}
|
Loading…
x
Reference in New Issue
Block a user