forked from jondot/goweight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (34 loc) · 787 Bytes
/
main.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
package main
import (
"encoding/json"
"fmt"
"github.com/jondot/goweight/pkg"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
var (
jsonOutput = kingpin.Flag("json", "Output json").Short('j').Bool()
buildTags = kingpin.Flag("tags", "Build tags").String()
)
func main() {
kingpin.Version(fmt.Sprintf("%s (%s)", version, commit))
kingpin.Parse()
weight := pkg.NewGoWeight()
if *buildTags != "" {
weight.BuildCmd = append(weight.BuildCmd, "-tags", *buildTags)
}
work := weight.BuildCurrent()
modules := weight.Process(work)
if *jsonOutput {
m, _ := json.Marshal(modules)
fmt.Print(string(m))
} else {
for _, module := range modules {
fmt.Printf("%8s %s\n", module.SizeHuman, module.Name)
}
}
}