-
Notifications
You must be signed in to change notification settings - Fork 21
/
merge.go
64 lines (51 loc) · 1.03 KB
/
merge.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
63
64
package command
import (
"fmt"
"io/ioutil"
"sort"
"strings"
"github.com/funkygao/gocli"
"github.com/funkygao/golib/gofmt"
)
type Merge struct {
Ui cli.Ui
Cmd string
}
func (this *Merge) Run(args []string) (exitCode int) {
if len(args) == 0 {
this.Ui.Error("missing path")
this.Ui.Output(this.Help())
return 2
}
return
}
func (this *Merge) render(path string) {
files, _ := ioutil.ReadDir(path)
m := make(map[string]int64)
for _, f := range files {
if f.Size() < 1 {
continue
}
segment := f.Name()[:5]
m[segment] += f.Size()
}
sortedNames := make([]string, 0, len(m))
for s := range m {
sortedNames = append(sortedNames, s)
}
sort.Strings(sortedNames)
for _, segment := range sortedNames {
size := m[segment]
this.Ui.Outputf("%10s %s", segment, gofmt.ByteSize(size))
}
}
func (*Merge) Synopsis() string {
return "Visualize segments merge process"
}
func (this *Merge) Help() string {
help := fmt.Sprintf(`
Usage: %s merge <path>
%s
`, this.Cmd, this.Synopsis())
return strings.TrimSpace(help)
}