-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathmain.go
83 lines (62 loc) · 1.81 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"fmt"
"strings"
"time"
"github.com/apex/log"
"github.com/apex/log/handlers/cli"
"github.com/dustin/go-humanize"
"github.com/tj/node-prune/internal/prune"
)
func init() {
log.SetHandler(cli.Default)
log.SetLevel(log.WarnLevel)
}
type arrayFlags []string
func (i *arrayFlags) String() string {
return strings.Join(*i, ", ")
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
// Globs of files that should not be pruned
var exclusionGlobs arrayFlags
// Globs of files that should always be pruned in addition to the defaults
var inclusionGlobs arrayFlags
func main() {
debug := flag.Bool("verbose", false, "Verbose log output.")
flag.Var(&exclusionGlobs, "exclude", "Glob of files that should not be pruned. Can be specified multiple times.")
flag.Var(&inclusionGlobs, "include", "Globs of files that should always be pruned in addition to the defaults. Can be specified multiple times.")
flag.Parse()
dir := flag.Arg(0)
start := time.Now()
if *debug {
log.SetLevel(log.DebugLevel)
}
var options []prune.Option
if dir != "" {
options = append(options, prune.WithDir(dir))
}
if len(exclusionGlobs) > 0 {
options = append(options, prune.WithExceptions(exclusionGlobs))
}
if len(inclusionGlobs) > 0 {
options = append(options, prune.WithGlobs(inclusionGlobs))
}
p := prune.New(options...)
stats, err := p.Prune()
if err != nil {
log.Fatalf("error: %s", err)
}
println()
defer println()
output("files total", humanize.Comma(stats.FilesTotal))
output("files removed", humanize.Comma(stats.FilesRemoved))
output("size removed", humanize.Bytes(uint64(stats.SizeRemoved)))
output("duration", time.Since(start).Round(time.Millisecond).String())
}
func output(name, val string) {
fmt.Printf("\x1b[1m%20s\x1b[0m %s\n", name, val)
}