git-project-manager/cmd/cache.go

39 lines
831 B
Go
Raw Normal View History

2023-12-04 21:53:01 +00:00
package cmd
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"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/projects"
2023-12-04 21:53:01 +00:00
)
2023-12-05 21:56:47 +00:00
var cache *projects.Cache
2023-12-04 21:53:01 +00:00
var cacheCmd = &cobra.Command{
2023-12-05 21:56:47 +00:00
Use: "cache",
Short: "Manage GitLab project cache",
2023-12-08 21:52:26 +00:00
Long: cacheCmdLong,
2023-12-10 05:05:39 +00:00
PersistentPreRun: runCacheCmd,
2023-12-05 21:56:47 +00:00
PersistentPostRun: postCacheCmd,
}
2023-12-10 05:05:39 +00:00
func runCacheCmd(cmd *cobra.Command, args []string) {
2023-12-05 21:56:47 +00:00
initProjectCache(cmd, args)
2023-12-10 05:05:39 +00:00
cache.LockCache()
2023-12-05 21:56:47 +00:00
}
func postCacheCmd(cmd *cobra.Command, args []string) {
postProjectCache(cmd, args)
2023-12-10 05:05:39 +00:00
cache.UnlockCache()
2023-12-04 21:53:01 +00:00
}
func init() {
rootCmd.AddCommand(cacheCmd)
2023-12-05 21:56:47 +00:00
cacheCmd.PersistentFlags().Duration("ttl", 48*time.Hour,
"Duration before cache is re-built in go time.Duration format")
2023-12-04 21:53:01 +00:00
2023-12-05 21:56:47 +00:00
viper.BindPFlags(cacheCmd.Flags())
2023-12-04 21:53:01 +00:00
}