ruspa/cmd/ru/main.go

69 lines
1.1 KiB
Go

package main
import (
"flag"
"fmt"
"time"
"git.lattuga.net/blallo/ruspa/tree"
)
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 tree.ErrUnknownUnit
}
}
func main() {
var path string
var depth int
var t tree.Node
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()
if depth == 0 {
t = tree.NewSingle(path)
} else {
t = tree.NewTop(path)
}
t.SetUnit(unit.String())
go t.Spawn(depth)
go t.Collect()
for !t.Complete() {
select {
case <-time.After(500 * time.Millisecond):
fmt.Printf("\033[H\033[2J")
fmt.Println(t)
}
}
}