62 lines
975 B
Go
62 lines
975 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type UnitValue struct {
|
|
unit string
|
|
}
|
|
|
|
func (u *UnitValue) String() string {
|
|
return u.unit
|
|
}
|
|
|
|
func (u *UnitValue) Set(value string) error {
|
|
switch value {
|
|
case "B":
|
|
u.unit = "B"
|
|
return nil
|
|
case "KB":
|
|
u.unit = "KB"
|
|
return nil
|
|
case "MB":
|
|
u.unit = "MB"
|
|
return nil
|
|
case "GB":
|
|
u.unit = "GB"
|
|
return nil
|
|
case "TB":
|
|
u.unit = "TB"
|
|
return nil
|
|
case "PB":
|
|
u.unit = "PB"
|
|
return nil
|
|
default:
|
|
return ErrUnknownUnit
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
var path string
|
|
var depth int
|
|
var unit = &UnitValue{unit: "KB"}
|
|
flag.StringVar(&path, "path", ".", "Path from where to start the walk from")
|
|
flag.IntVar(&depth, "depth", 0, "Depth to display")
|
|
flag.Var(unit, "unit", "Unit in which to report size")
|
|
flag.Parse()
|
|
|
|
t := NewTop(path)
|
|
t.SetUnit(unit.String())
|
|
go t.Spawn(depth)
|
|
go t.Collect()
|
|
for {
|
|
select {
|
|
case <-time.After(500 * time.Millisecond):
|
|
fmt.Printf("\033[H\033[2J")
|
|
fmt.Println(t)
|
|
}
|
|
}
|
|
}
|