git-project-manager/cmd/cache.go

41 lines
977 B
Go

package cmd
import (
"time"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/projects"
)
const desc = `Contains sub-commands for managing project cache.
The project cache keeps this speedy, without smashing against the GitLab
API every time a new project is added / searched for`
var cache *projects.Cache
var cacheCmd = &cobra.Command{
Use: "cache",
Short: "Manage GitLab project cache",
Long: desc,
PersistentPreRun: initCacheCmd,
PersistentPostRun: postCacheCmd,
}
func initCacheCmd(cmd *cobra.Command, args []string) {
initProjectCache(cmd, args)
}
func postCacheCmd(cmd *cobra.Command, args []string) {
postProjectCache(cmd, args)
}
func init() {
rootCmd.AddCommand(cacheCmd)
cacheCmd.PersistentFlags().Duration("ttl", 48*time.Hour,
"Duration before cache is re-built in go time.Duration format")
viper.BindPFlags(cacheCmd.Flags())
}