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 was merged in pull request #4.
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

@@ -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 {