Package subcommand code

This commit is contained in:
2024-12-30 15:50:31 -05:00
parent 96378d047e
commit b9d7d5a4f2
51 changed files with 357 additions and 295 deletions

31
cmd/cache/cache.go vendored
View File

@@ -1,34 +1,43 @@
package cmd
package cache
import (
"time"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util"
)
var cacheCmd = &cobra.Command{
var CacheCmd = &cobra.Command{
Use: "cache",
Aliases: []string{"a", "ln"},
Short: "Manage Git project cache",
Long: cacheCmdLong,
Long: util.CacheCmdLong,
}
var utils *util.Utils
func runCacheCmd(cmd *cobra.Command, args []string) {
initProjectCache(cmd, args)
projectCache.LockCache()
utils = util.MustFromCtx(cmd.Context())
utils.InitProjectCache(cmd, args)
utils.Cache().LockCache()
}
func postCacheCmd(cmd *cobra.Command, args []string) {
postProjectCache(cmd, args)
projectCache.UnlockCache()
utils.PostProjectCache(cmd, args)
utils.Cache().UnlockCache()
}
func init() {
rootCmd.AddCommand(cacheCmd)
cacheCmd.PersistentFlags().Duration("ttl", 48*time.Hour,
CacheCmd.PersistentFlags().Duration("ttl", 48*time.Hour,
"Duration before cache is re-built in go time.Duration format")
viper.BindPFlags(cacheCmd.Flags())
viper.BindPFlags(CacheCmd.Flags())
CacheCmd.AddCommand(clearCmd)
CacheCmd.AddCommand(dumpCmd)
CacheCmd.AddCommand(loadCmd)
CacheCmd.AddCommand(unlockCmd)
}