Added command to clear glide cache
diff --git a/action/cache.go b/action/cache.go
new file mode 100644
index 0000000..9896f21
--- /dev/null
+++ b/action/cache.go
@@ -0,0 +1,29 @@
+package action
+
+import (
+ "os"
+
+ "github.com/Masterminds/glide/cache"
+ "github.com/Masterminds/glide/msg"
+)
+
+// CacheClear clears the Glide cache
+func CacheClear() {
+ l, err := cache.Location()
+ if err != nil {
+ msg.Die("Unable to clear the cache: %s", err)
+ }
+
+ err = os.RemoveAll(l)
+ if err != nil {
+ msg.Die("Unable to clear the cache: %s", err)
+ }
+
+ cache.SetupReset()
+ err = cache.Setup()
+ if err != nil {
+ msg.Die("Unable to clear the cache: %s", err)
+ }
+
+ msg.Info("Glide cache has been cleared.")
+}
diff --git a/cache/cache.go b/cache/cache.go
index 5d6a49d..55b059a 100644
--- a/cache/cache.go
+++ b/cache/cache.go
@@ -27,7 +27,8 @@
var setupMutex sync.Mutex
-func setup() error {
+// Setup creates the cache location.
+func Setup() error {
setupMutex.Lock()
defer setupMutex.Unlock()
@@ -52,10 +53,16 @@
return nil
}
+// SetupReset resets if setup has been completed. The next time setup is run
+// it will attempt a full setup.
+func SetupReset() {
+ isSetup = false
+}
+
// Location returns the location of the cache.
func Location() (string, error) {
p := filepath.Join(gpath.Home(), "cache")
- err := setup()
+ err := Setup()
return p, err
}
diff --git a/glide.go b/glide.go
index 2f75f07..a9f43ea 100644
--- a/glide.go
+++ b/glide.go
@@ -639,6 +639,14 @@
},
},
{
+ Name: "cache-clear",
+ ShortName: "cc",
+ Usage: "Clears the Glide cache.",
+ Action: func(c *cli.Context) {
+ action.CacheClear()
+ },
+ },
+ {
Name: "about",
Usage: "Learn about Glide",
Action: func(c *cli.Context) {