aboutsummaryrefslogtreecommitdiffhomepage
path: root/commands/mod.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-02-19 16:59:54 +0100
committerBjørn Erik Pedersen <[email protected]>2020-02-19 17:14:35 +0100
commitdce210ab56fc885818fc5d1a084a1c3ba84e7929 (patch)
tree538afbc8dfc1ed805c874f53248e25b506ebf6cc /commands/mod.go
parent0b96aba022d51cf9939605c029bb8dba806653a1 (diff)
downloadhugo-dce210ab56fc885818fc5d1a084a1c3ba84e7929.tar.gz
hugo-dce210ab56fc885818fc5d1a084a1c3ba84e7929.zip
modules: Improve "hugo mod clean"
* Only clean project modules * Optional glob pattern of module paths to clean Closes #6907
Diffstat (limited to 'commands/mod.go')
-rw-r--r--commands/mod.go46
1 files changed, 25 insertions, 21 deletions
diff --git a/commands/mod.go b/commands/mod.go
index 61e3c74e6..0b88df666 100644
--- a/commands/mod.go
+++ b/commands/mod.go
@@ -49,6 +49,30 @@ func (c *modCmd) newVerifyCmd() *cobra.Command {
return verifyCmd
}
+func (c *modCmd) newCleanCmd() *cobra.Command {
+ var pattern string
+ cmd := &cobra.Command{
+ Use: "clean",
+ Short: "Delete the Hugo Module cache for the current project.",
+ Long: `Delete the Hugo Module cache for the current project.
+
+Note that after you run this command, all of your dependencies will be re-downloaded next time you run "hugo".
+
+Also note that if you configure a positive maxAge for the "modules" file cache, it will also be cleaned as part of "hugo --gc".
+
+`,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return c.withModsClient(true, func(c *modules.Client) error {
+ return c.Clean(pattern)
+ })
+ },
+ }
+
+ cmd.Flags().StringVarP(&pattern, "pattern", "", "", `pattern matching module paths to clean (all if not set), e.g. "**hugo*"`)
+
+ return cmd
+}
+
func (b *commandsBuilder) newModCmd() *modCmd {
c := &modCmd{}
@@ -215,27 +239,7 @@ If a module is vendored, that is where Hugo will look for it's dependencies.
})
},
},
- &cobra.Command{
- Use: "clean",
- Short: "Delete the entire Hugo Module cache.",
- Long: `Delete the entire Hugo Module cache.
-
-Note that after you run this command, all of your dependencies will be re-downloaded next time you run "hugo".
-
-Also note that if you configure a positive maxAge for the "modules" file cache, it will also be cleaned as part of "hugo --gc".
-
-`,
- RunE: func(cmd *cobra.Command, args []string) error {
- com, err := c.initConfig(true)
- if err != nil {
- return err
- }
-
- _, err = com.hugo().FileCaches.ModulesCache().Prune(true)
- return err
-
- },
- },
+ c.newCleanCmd(),
)
c.baseBuilderCmd = b.newBuilderCmd(cmd)