Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
cmd: improved cache-clear command (#16)
Browse files Browse the repository at this point in the history
Added a message about the successful deletion of the cache, and now,
in case of a strange path, a message is displayed without panic.
  • Loading branch information
i582 authored Jul 1, 2021
1 parent 133b4ec commit 81ffbf5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/cache_clear.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package cmd

import (
"fmt"
"os"

"github.com/i582/cfmt/cmd/cfmt"
)

func CacheClear() (int, error) {
cacheDir := DefaultCacheDir()
if cacheDir == "/" || cacheDir == "" {
panic(fmt.Sprintf("attempted to rm -rf %s", cacheDir))
cfmt.Printf("Cache clearing error: attempted to {{rm -rf %s}}::red", cacheDir)
return 2, nil
}
err := os.RemoveAll(cacheDir)
cfmt.Println("The cache has been {{successfully}}::green deleted.")
return 0, err
}

0 comments on commit 81ffbf5

Please sign in to comment.