Package subcommand code

This commit is contained in:
2024-12-30 14:54:32 -05:00
parent 888ee5ea4a
commit 96378d047e
19 changed files with 564 additions and 412 deletions

31
cmd/cache/cache_clear.go vendored Normal file
View File

@@ -0,0 +1,31 @@
package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/exp/slog"
)
const longDesc = `Used to reset a project cache, forcing it to be rebuilt.
If --clearAliases is provided, will also reset aliases. Use with caution.`
var clearCmd = &cobra.Command{
Use: "clear",
Short: "Clear Git Project Cache",
PreRun: runCacheCmd,
PostRun: postCacheCmd,
Long: longDesc,
Run: clearCache,
}
func clearCache(cmd *cobra.Command, args []string) {
slog.Debug("Preparing to clear local cache")
projectCache.Clear(conf.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"))
}