-
Notifications
You must be signed in to change notification settings - Fork 1
/
diagnose.go
62 lines (53 loc) · 1.78 KB
/
diagnose.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"strings"
)
var totalSize int64 = 0
//DiagnoseAll: Get the size of each directory and print it on the command line.
func DiagnoseAll() {
for _, dir := range AllDirectories() {
dirSlice := strings.Split(dir, "/")
dirName := dirSlice[len(dirSlice)-1]
if dir == XcCache() {
dirName = "XCode Cache"
}
diagnoseDir(dir, dirName)
}
mbSizeTotal := SizeInMB(totalSize)
if mbSizeTotal >= 1000.0 {
gbSize := RoundGB(SizeMBToGB(mbSizeTotal))
gbStr := fmt.Sprintf("%.2f", gbSize)
fmt.Printf("\n%s %s %s \n", blue("Total:"), addPadding("Total:"), red(gbStr+" GB"))
} else {
mbStr := fmt.Sprintf("%.1f", mbSizeTotal)
fmt.Printf("%s %s %s \n", blue("Total:"), addPadding("Total:"), green(mbStr+" MB"))
}
fmt.Printf("\nType %s or %s to clear everything. Archives and the last installed iOS version in iOS DeviceSupport won't be deleted.", red("xcclear -p"), red("xcclear --purge"))
}
//diagnoseDir: Get the size of the directory passed in as the path parameter and print description message.
func diagnoseDir(path string, dirName string) {
sizeOfDir, err := DirSize(path)
totalSize = totalSize + sizeOfDir
if err != nil {
fmt.Printf("%s: - directory doesn't exist.\n", dirName)
return
}
mbSize := SizeInMB(sizeOfDir)
if mbSize >= 1000.0 {
gbSize := RoundGB(SizeMBToGB(mbSize))
gbStr := fmt.Sprintf("%.2f", gbSize)
fmt.Printf("%s: %s %s \n", dirName, addPadding(dirName), red(gbStr+" GB"))
} else {
mbStr := fmt.Sprintf("%.1f", mbSize)
fmt.Printf("%s: %s %s \n", dirName, addPadding(dirName), green(mbStr+" MB"))
}
}
//addPadding: Add a padding between the directory name and the size of the directory.
func addPadding(title string) string {
padding := ""
for i := 0; i < (40 - len(title)); i++ {
padding = padding + "-"
}
return padding
}