@@ -19,6 +19,18 @@ import (
19
19
"github.com/spf13/cobra"
20
20
)
21
21
22
+ const (
23
+ bite = 1 << (10 * iota )
24
+ kilobyte
25
+ megabyte
26
+ gigabyte
27
+ terabyte
28
+ petabyte
29
+ exabyte
30
+ zettabyte
31
+ yottabyte
32
+ )
33
+
22
34
var printPrompt = color .New (color .FgWhite ).PrintfFunc ()
23
35
var spinner = sp .New (sp .CharSets [24 ], 100 * time .Millisecond )
24
36
@@ -46,6 +58,48 @@ func printNotYetFinished(cmd *cobra.Command) {
46
58
color .Yellow ("%s command is not yet implemented" , cmd .Name ())
47
59
}
48
60
61
+ func printByteInfo (l int ) string {
62
+ length := struct {
63
+ name string
64
+ value int
65
+ }{"" , 0 }
66
+
67
+ switch {
68
+ // yottabyte and zettabyte overflow int
69
+ // case l > yottabyte:
70
+ // length.name = "YB"
71
+ // length.value = l / yottabyte
72
+ // case l > zettabyte:
73
+ // length.name = "ZB"
74
+ // length.value = l / zettabyte
75
+ case l >= exabyte :
76
+ length .name = "EB"
77
+ length .value = l / exabyte
78
+ case l >= petabyte :
79
+ length .name = "PB"
80
+ length .value = l / petabyte
81
+ case l >= terabyte :
82
+ length .name = "TB"
83
+ length .value = l / terabyte
84
+ case l >= gigabyte :
85
+ length .name = "GB"
86
+ length .value = l / gigabyte
87
+ case l >= megabyte :
88
+ length .name = "MB"
89
+ length .value = l / megabyte
90
+ case l >= kilobyte :
91
+ length .name = "KB"
92
+ length .value = l / kilobyte
93
+ default :
94
+ length .name = "byte"
95
+ length .value = l
96
+ }
97
+ if length .value != 1 {
98
+ length .name += "s"
99
+ }
100
+ return fmt .Sprintf ("%v %s" , length .value , length .name )
101
+ }
102
+
49
103
func printDatasetRefInfo (i int , ref repo.DatasetRef ) {
50
104
white := color .New (color .FgWhite ).SprintFunc ()
51
105
cyan := color .New (color .FgCyan ).SprintFunc ()
@@ -68,7 +122,7 @@ func printDatasetRefInfo(i int, ref repo.DatasetRef) {
68
122
}
69
123
}
70
124
if ds != nil && ds .Structure != nil {
71
- fmt .Printf (" %d bytes , %d entries, %d errors" , ds .Structure .Length , ds .Structure .Entries , ds .Structure .ErrCount )
125
+ fmt .Printf (" %s , %d entries, %d errors" , printByteInfo ( ds .Structure .Length ) , ds .Structure .Entries , ds .Structure .ErrCount )
72
126
}
73
127
74
128
fmt .Println ()
0 commit comments