|
|
@@ -0,0 +1,50 @@
|
|
|
+package cmd
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+
|
|
|
+ "github.com/spf13/cobra"
|
|
|
+
|
|
|
+ "github.com/runningwater/gohub/pkg/cache"
|
|
|
+ "github.com/runningwater/gohub/pkg/console"
|
|
|
+)
|
|
|
+
|
|
|
+var CmdCache = &cobra.Command{
|
|
|
+ Use: "cache",
|
|
|
+ Short: "Cache Management",
|
|
|
+}
|
|
|
+
|
|
|
+var CmdCacheClear = &cobra.Command{
|
|
|
+ Use: "clear",
|
|
|
+ Short: "Clear Cache",
|
|
|
+ Run: runCacheClear,
|
|
|
+}
|
|
|
+
|
|
|
+var CmdCacheForget = &cobra.Command{
|
|
|
+ Use: "forget",
|
|
|
+ Short: "Delete redis key, example: gohub cache forget key",
|
|
|
+ Run: runCacheForget,
|
|
|
+}
|
|
|
+
|
|
|
+func runCacheClear(cmd *cobra.Command, args []string) {
|
|
|
+ cache.Flush()
|
|
|
+ console.Success("Cache cleared")
|
|
|
+}
|
|
|
+
|
|
|
+func runCacheForget(cmd *cobra.Command, args []string) {
|
|
|
+ cache.Forget(cacheKey)
|
|
|
+ console.Success(fmt.Sprintf("Cache key [%s] deleted", cacheKey))
|
|
|
+}
|
|
|
+
|
|
|
+// forget 命令的选项
|
|
|
+var cacheKey string
|
|
|
+
|
|
|
+func init() {
|
|
|
+ // 注册 cache 命令的子命令
|
|
|
+ CmdCache.AddCommand(CmdCacheClear, CmdCacheForget)
|
|
|
+
|
|
|
+ // 注册 forget 命令的选项
|
|
|
+ CmdCacheForget.Flags().StringVarP(&cacheKey, "key", "k", "", "Cache key")
|
|
|
+ _ = CmdCacheForget.MarkFlagRequired("key")
|
|
|
+
|
|
|
+}
|