Skip to content

Commit

Permalink
cmd/clean: Don't clean if cache is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed Sep 22, 2023
1 parent c341483 commit 22a6fd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cmd/hvm/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion cmd/hvm/testscripts/clean.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22a6fd4

Please sign in to comment.