summaryrefslogtreecommitdiffstats
path: root/modules/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/client.go')
-rw-r--r--modules/client.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/client.go b/modules/client.go
index 601b5e109..a82300b37 100644
--- a/modules/client.go
+++ b/modules/client.go
@@ -26,6 +26,9 @@ import (
"path/filepath"
"regexp"
+ "github.com/gobwas/glob"
+ hglob "github.com/gohugoio/hugo/hugofs/glob"
+
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugofs/files"
@@ -339,6 +342,38 @@ func (c *Client) Verify(clean bool) error {
return err
}
+func (c *Client) Clean(pattern string) error {
+ mods, err := c.listGoMods()
+ if err != nil {
+ return err
+ }
+
+ var g glob.Glob
+
+ if pattern != "" {
+ var err error
+ g, err = hglob.GetGlob(pattern)
+ if err != nil {
+ return err
+ }
+ }
+
+ for _, m := range mods {
+ if m.Replace != nil || m.Main {
+ continue
+ }
+
+ if g != nil && !g.Match(m.Path) {
+ continue
+ }
+ _, err = hugofs.MakeReadableAndRemoveAllModulePkgDir(c.fs, m.Dir)
+ if err == nil {
+ c.logger.FEEDBACK.Printf("hugo: cleaned module cache for %q", m.Path)
+ }
+ }
+ return err
+}
+
func (c *Client) runVerify() error {
return c.runGo(context.Background(), ioutil.Discard, "mod", "verify")
}