From 396f5b9fcb1682734c167af0781399cce8a024f5 Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 19 Apr 2025 16:00:43 -0400 Subject: [PATCH] adding view all ability --- README.md | 4 ++++ cmd/view.go | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 568241c..d8615f8 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,10 @@ Saved commands can be viewed with: ```bash mctl view ``` +All saved commands can be viewed with: +```bash +mctl view all +``` ### Running saved commands Commands that have been saved can be run with: diff --git a/cmd/view.go b/cmd/view.go index a6f608e..1c95609 100644 --- a/cmd/view.go +++ b/cmd/view.go @@ -6,6 +6,7 @@ package cmd import ( "errors" "fmt" + "strings" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -16,7 +17,7 @@ var viewCmd = &cobra.Command{ Use: "view ", Example: "mctl view test", 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) { var cm map[string]any cmdMap := viper.Get("customcmd") @@ -26,6 +27,17 @@ var viewCmd = &cobra.Command{ } 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]] if !ok { fmt.Println("command not found")