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
|
|
|
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
|
|
|
|
|
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",
|
|
|
|
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)
|
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
|
|
|
}
|