mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
commands: Add --all flag to hugo mod clean
This commit is contained in:
parent
3d3fa5c3fe
commit
760a87a45a
1 changed files with 15 additions and 0 deletions
|
@ -18,6 +18,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/modules"
|
"github.com/gohugoio/hugo/modules"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -49,8 +50,11 @@ func (c *modCmd) newVerifyCmd() *cobra.Command {
|
||||||
return verifyCmd
|
return verifyCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var moduleNotFoundRe = regexp.MustCompile("module.*not found")
|
||||||
|
|
||||||
func (c *modCmd) newCleanCmd() *cobra.Command {
|
func (c *modCmd) newCleanCmd() *cobra.Command {
|
||||||
var pattern string
|
var pattern string
|
||||||
|
var all bool
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "clean",
|
Use: "clean",
|
||||||
Short: "Delete the Hugo Module cache for the current project.",
|
Short: "Delete the Hugo Module cache for the current project.",
|
||||||
|
@ -62,6 +66,16 @@ Also note that if you configure a positive maxAge for the "modules" file cache,
|
||||||
|
|
||||||
`,
|
`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if all {
|
||||||
|
com, err := c.initConfig(false)
|
||||||
|
|
||||||
|
if err != nil && !moduleNotFoundRe.MatchString(err.Error()) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = com.hugo().FileCaches.ModulesCache().Prune(true)
|
||||||
|
return err
|
||||||
|
}
|
||||||
return c.withModsClient(true, func(c *modules.Client) error {
|
return c.withModsClient(true, func(c *modules.Client) error {
|
||||||
return c.Clean(pattern)
|
return c.Clean(pattern)
|
||||||
})
|
})
|
||||||
|
@ -69,6 +83,7 @@ Also note that if you configure a positive maxAge for the "modules" file cache,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().StringVarP(&pattern, "pattern", "", "", `pattern matching module paths to clean (all if not set), e.g. "**hugo*"`)
|
cmd.Flags().StringVarP(&pattern, "pattern", "", "", `pattern matching module paths to clean (all if not set), e.g. "**hugo*"`)
|
||||||
|
cmd.Flags().BoolVarP(&all, "all", "", false, "clean entire module cache")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue