Package subcommand code
This commit is contained in:
31
cmd/cache/cache.go
vendored
31
cmd/cache/cache.go
vendored
@ -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)
|
||||
}
|
||||
|
5
cmd/cache/cache_clear.go
vendored
5
cmd/cache/cache_clear.go
vendored
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
@ -21,11 +21,10 @@ var clearCmd = &cobra.Command{
|
||||
|
||||
func clearCache(cmd *cobra.Command, args []string) {
|
||||
slog.Debug("Preparing to clear local cache")
|
||||
projectCache.Clear(conf.Cache.Clear.ClearAliases)
|
||||
utils.Cache().Clear(utils.Config().Cache.Clear.ClearAliases)
|
||||
}
|
||||
|
||||
func init() {
|
||||
cacheCmd.AddCommand(clearCmd)
|
||||
clearCmd.Flags().Bool("clearAliases", false, "Will also clear aliases from the cache, use with caution")
|
||||
viper.BindPFlag("cache.clear.clearAliases", clearCmd.LocalFlags().Lookup("clearAliases"))
|
||||
}
|
||||
|
13
cmd/cache/cache_dump.go
vendored
13
cmd/cache/cache_dump.go
vendored
@ -1,10 +1,12 @@
|
||||
package cmd
|
||||
package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util"
|
||||
)
|
||||
|
||||
var dumpCmd = &cobra.Command{
|
||||
@ -17,16 +19,15 @@ var dumpCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func runCacheDunpCmd(cmd *cobra.Command, args []string) {
|
||||
remotes := viper.GetStringSlice(FlagRemote)
|
||||
if conf.Dump.Full {
|
||||
fmt.Println(projectCache.DumpString(true, searchStringFromArgs(args), remotes...))
|
||||
remotes := viper.GetStringSlice(util.FlagRemote)
|
||||
if utils.Config().Dump.Full {
|
||||
fmt.Println(utils.Cache().DumpString(true, utils.SearchStringFromArgs(args), remotes...))
|
||||
} else {
|
||||
plog.Info(projectCache.String())
|
||||
utils.Logger().Info(utils.Cache().String())
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
cacheCmd.AddCommand(dumpCmd)
|
||||
dumpCmd.PersistentFlags().BoolP("full", "f", false, "Dumps entire cache")
|
||||
viper.BindPFlag("dump.full", dumpCmd.LocalFlags().Lookup("full"))
|
||||
}
|
||||
|
14
cmd/cache/cache_load.go
vendored
14
cmd/cache/cache_load.go
vendored
@ -1,8 +1,10 @@
|
||||
package cmd
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util"
|
||||
)
|
||||
|
||||
var loadCmd = &cobra.Command{
|
||||
@ -17,15 +19,13 @@ wants to find a new project.`,
|
||||
}
|
||||
|
||||
func loadCache(cmd *cobra.Command, args []string) {
|
||||
remotes := viper.GetStringSlice(FlagRemote)
|
||||
projectCache.Refresh(remotes...)
|
||||
remotes := viper.GetStringSlice(util.FlagRemote)
|
||||
utils.Cache().Refresh(remotes...)
|
||||
}
|
||||
|
||||
func init() {
|
||||
cacheCmd.AddCommand(loadCmd)
|
||||
|
||||
loadCmd.PersistentFlags().Bool(FlagOwnerOnly, true,
|
||||
loadCmd.PersistentFlags().Bool(util.FlagOwnerOnly, true,
|
||||
"Only load projects that you are owner of")
|
||||
|
||||
viper.BindPFlag(ViperCacheLoadOwnerOnly, loadCmd.Flag(FlagOwnerOnly))
|
||||
viper.BindPFlag(util.ViperCacheLoadOwnerOnly, loadCmd.Flag(util.FlagOwnerOnly))
|
||||
}
|
||||
|
20
cmd/cache/cache_unlock.go
vendored
20
cmd/cache/cache_unlock.go
vendored
@ -1,9 +1,11 @@
|
||||
package cmd
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/git-project-manager/cmd/util"
|
||||
)
|
||||
|
||||
var unlockCmd = &cobra.Command{
|
||||
@ -11,21 +13,21 @@ var unlockCmd = &cobra.Command{
|
||||
Short: "unlock Git project cache",
|
||||
Long: `unlocks cache to display`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
initProjectCache(cmd, args)
|
||||
if viper.GetBool(ViperCacheUnlockForce) {
|
||||
projectCache.UnlockCache()
|
||||
utils = util.MustFromCtx(cmd.Context())
|
||||
utils.InitProjectCache(cmd, args)
|
||||
if viper.GetBool(util.ViperCacheUnlockForce) {
|
||||
utils.Cache().UnlockCache()
|
||||
} else if yes, _ := pterm.DefaultInteractiveConfirm.
|
||||
WithDefaultValue(false).
|
||||
Show("Are you sure you want to manually unlock?"); yes {
|
||||
projectCache.UnlockCache()
|
||||
utils.Cache().UnlockCache()
|
||||
} else {
|
||||
plog.Error("You failed to confirm cache unlock")
|
||||
utils.Logger().Error("You failed to confirm cache unlock")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
cacheCmd.AddCommand(unlockCmd)
|
||||
unlockCmd.PersistentFlags().BoolP(FlagCacheForce, "f", false, "force unlocks cache (don't ask)")
|
||||
viper.BindPFlag(ViperCacheUnlockForce, unlockCmd.LocalFlags().Lookup(FlagCacheForce))
|
||||
unlockCmd.PersistentFlags().BoolP(util.FlagCacheForce, "f", false, "force unlocks cache (don't ask)")
|
||||
viper.BindPFlag(util.ViperCacheUnlockForce, unlockCmd.LocalFlags().Lookup(util.FlagCacheForce))
|
||||
}
|
||||
|
Reference in New Issue
Block a user