From d69bb677897342983f5917881c0bd84ce7789c71 Mon Sep 17 00:00:00 2001 From: i582 Date: Thu, 1 Jul 2021 00:08:39 +0300 Subject: [PATCH] cmd: added cache-clear command --- cmd/cache_clear.go | 15 +++++++++++++++ cmd/main.go | 8 ++++++++ 2 files changed, 23 insertions(+) create mode 100644 cmd/cache_clear.go diff --git a/cmd/cache_clear.go b/cmd/cache_clear.go new file mode 100644 index 0000000..ed051fe --- /dev/null +++ b/cmd/cache_clear.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "fmt" + "os" +) + +func CacheClear() (int, error) { + cacheDir := DefaultCacheDir() + if cacheDir == "/" || cacheDir == "" { + panic(fmt.Sprintf("attempted to rm -rf %s", cacheDir)) + } + err := os.RemoveAll(cacheDir) + return 0, err +} diff --git a/cmd/main.go b/cmd/main.go index f4588f7..fb792dd 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -83,6 +83,14 @@ func Main() { }, }) + app.Commands = append(app.Commands, &cmd.Command{ + Name: "cache-clear", + Description: "The command clears the cache", + Action: func(ctx *cmd.AppContext) (int, error) { + return CacheClear() + }, + }) + app.Commands = append(app.Commands, &cmd.Command{ Name: "init", Description: "The command to create a template palette in the project folder",