2025-06-17 23:12:49 -04:00
|
|
|
/*
|
|
|
|
Copyright © 2025 Jake jake.young.dev@gmail.com
|
|
|
|
*/
|
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.jakeyoungdev.com/jake/mctl/database"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var viewCmd = &cobra.Command{
|
2025-06-19 17:23:17 -04:00
|
|
|
Use: "view",
|
|
|
|
Example: "mctl command view",
|
|
|
|
Short: "view all saved commands",
|
|
|
|
SilenceUsage: true,
|
2025-06-17 23:12:49 -04:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
db, err := database.New()
|
|
|
|
cobra.CheckErr(err)
|
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
ts, err := db.GetAllCmds()
|
2025-06-19 17:23:17 -04:00
|
|
|
if err.Error() == ErrInit {
|
|
|
|
fmt.Println(ErrInitRsp)
|
|
|
|
return
|
|
|
|
}
|
2025-06-17 23:12:49 -04:00
|
|
|
cobra.CheckErr(err)
|
|
|
|
|
|
|
|
for _, s := range ts {
|
|
|
|
fmt.Println("-----")
|
|
|
|
fmt.Printf("Name: %s\n", s.Name)
|
|
|
|
fmt.Printf("Command: %s\n", s.Command)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
CommandCmd.AddCommand(viewCmd)
|
|
|
|
}
|