feature/view-all #5

Merged
jake merged 2 commits from feature/view-all into main 2025-04-20 05:28:56 +00:00
3 changed files with 18 additions and 2 deletions

View File

@ -43,6 +43,10 @@ Saved commands can be viewed with:
```bash ```bash
mctl view <name> mctl view <name>
``` ```
All saved commands can be viewed with:
```bash
mctl view all
```
### Running saved commands ### Running saved commands
Commands that have been saved can be run with: Commands that have been saved can be run with:

View File

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

View File

@ -6,6 +6,7 @@ package cmd
import ( import (
"errors" "errors"
"fmt" "fmt"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -16,7 +17,7 @@ var viewCmd = &cobra.Command{
Use: "view <name>", Use: "view <name>",
Example: "mctl view test", Example: "mctl view test",
Short: "View saved commands", Short: "View saved commands",
Long: `Load command using the supplied name and displays it in the terminal`, Long: `Load command using the supplied name and displays it in the terminal, 'all' will list every saved command`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var cm map[string]any var cm map[string]any
cmdMap := viper.Get("customcmd") cmdMap := viper.Get("customcmd")
@ -26,6 +27,17 @@ var viewCmd = &cobra.Command{
} }
cm = cmdMap.(map[string]any) cm = cmdMap.(map[string]any)
if strings.EqualFold(args[0], "all") {
//show all commands
fmt.Println("\nCommands: ")
for k, v := range cm {
fmt.Printf("%s - %s\n", k, v)
}
fmt.Println()
return
}
custom, ok := cm[args[0]] custom, ok := cm[args[0]]
if !ok { if !ok {
fmt.Println("command not found") fmt.Println("command not found")