git-project-manager/cmd/cache/cache.go

44 lines
918 B
Go
Raw Normal View History

2024-12-30 20:50:31 +00:00
package cache
2023-12-04 21:53:01 +00:00
import (
2023-12-05 21:56:47 +00:00
"time"
2023-12-04 21:53:01 +00:00
"github.com/spf13/cobra"
2023-12-05 21:56:47 +00:00
"github.com/spf13/viper"
2024-12-30 20:50:31 +00:00
"gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util"
2023-12-04 21:53:01 +00:00
)
2024-12-30 20:50:31 +00:00
var CacheCmd = &cobra.Command{
Use: "cache",
Aliases: []string{"a", "ln"},
2024-12-27 22:42:44 +00:00
Short: "Manage Git project cache",
2024-12-30 20:50:31 +00:00
Long: util.CacheCmdLong,
2023-12-05 21:56:47 +00:00
}
2024-12-30 20:50:31 +00:00
var utils *util.Utils
2023-12-10 05:05:39 +00:00
func runCacheCmd(cmd *cobra.Command, args []string) {
2024-12-30 20:50:31 +00:00
utils = util.MustFromCtx(cmd.Context())
utils.InitProjectCache(cmd, args)
utils.Cache().LockCache()
2023-12-05 21:56:47 +00:00
}
func postCacheCmd(cmd *cobra.Command, args []string) {
2024-12-30 20:50:31 +00:00
utils.PostProjectCache(cmd, args)
utils.Cache().UnlockCache()
2023-12-04 21:53:01 +00:00
}
func init() {
2024-12-30 20:50:31 +00:00
CacheCmd.PersistentFlags().Duration("ttl", 48*time.Hour,
2023-12-05 21:56:47 +00:00
"Duration before cache is re-built in go time.Duration format")
2023-12-04 21:53:01 +00:00
2024-12-30 20:50:31 +00:00
viper.BindPFlags(CacheCmd.Flags())
CacheCmd.AddCommand(clearCmd)
CacheCmd.AddCommand(dumpCmd)
CacheCmd.AddCommand(loadCmd)
CacheCmd.AddCommand(unlockCmd)
2023-12-04 21:53:01 +00:00
}