From 22a6fd484b3dd6b026763648c424fd50e7cf31f2 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Fri, 22 Sep 2023 16:04:04 -0700 Subject: [PATCH] cmd/clean: Don't clean if cache is empty --- cmd/hvm/clean.go | 11 +++++++++++ cmd/hvm/testscripts/clean.txt | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/hvm/clean.go b/cmd/hvm/clean.go index 0e1eb3e..f3d6a22 100644 --- a/cmd/hvm/clean.go +++ b/cmd/hvm/clean.go @@ -44,6 +44,17 @@ func init() { // clean cleans the cache, excluding the version installed with the "install" // command. func clean() error { + + cacheSize, err := getCacheSize() + if err != nil { + return err + } + + if cacheSize == 0 { + fmt.Println("The cache is already empty.") + return nil + } + fmt.Println("This will delete cached versions of the Hugo executable.") var r string diff --git a/cmd/hvm/testscripts/clean.txt b/cmd/hvm/testscripts/clean.txt index 0e2d261..6db1433 100644 --- a/cmd/hvm/testscripts/clean.txt +++ b/cmd/hvm/testscripts/clean.txt @@ -7,13 +7,17 @@ [windows] env LocalAppData=cache [windows] env AppData=config -# Test +# Test 1: cache is not empty stdin input.txt exec hvm clean stdout 'This will delete cached versions of the Hugo executable.' stdout 'Are you sure you want to clean the cache\? \(y/N\): ' stdout 'Cache cleaned.' +# Test 2: cache is empty +exec hvm clean +stdout 'The cache is already empty.' + # Files -- input.txt -- y