Package the logic. Create cli entrypoint.

This commit is contained in:
Blallo 2020-03-05 14:32:50 +01:00
parent ce417a1df6
commit 6ccb16e7bd
No known key found for this signature in database
GPG key ID: 0CBE577C9B72DC3F
6 changed files with 15 additions and 8 deletions

View file

@ -4,6 +4,8 @@ import (
"flag" "flag"
"fmt" "fmt"
"time" "time"
"git.lattuga.net/blallo/ruspa/tree"
) )
type UnitValue struct { type UnitValue struct {
@ -35,24 +37,29 @@ func (u *UnitValue) Set(value string) error {
u.unit = "PB" u.unit = "PB"
return nil return nil
default: default:
return ErrUnknownUnit return tree.ErrUnknownUnit
} }
} }
func main() { func main() {
var path string var path string
var depth int var depth int
var t tree.Node
var unit = &UnitValue{unit: "KB"} var unit = &UnitValue{unit: "KB"}
flag.StringVar(&path, "path", ".", "Path from where to start the walk from") flag.StringVar(&path, "path", ".", "Path from where to start the walk from")
flag.IntVar(&depth, "depth", 0, "Depth to display") flag.IntVar(&depth, "depth", 0, "Depth to display")
flag.Var(unit, "unit", "Unit in which to report size") flag.Var(unit, "unit", "Unit in which to report size")
flag.Parse() flag.Parse()
t := NewTop(path) if depth == 0 {
t = tree.NewSingle(path)
} else {
t = tree.NewTop(path)
}
t.SetUnit(unit.String()) t.SetUnit(unit.String())
go t.Spawn(depth) go t.Spawn(depth)
go t.Collect() go t.Collect()
for { for !t.Complete() {
select { select {
case <-time.After(500 * time.Millisecond): case <-time.After(500 * time.Millisecond):
fmt.Printf("\033[H\033[2J") fmt.Printf("\033[H\033[2J")

View file

@ -1,4 +1,4 @@
package main package tree
import ( import (
"os" "os"

View file

@ -1,4 +1,4 @@
package main package tree
import ( import (
"io/ioutil" "io/ioutil"

View file

@ -1,4 +1,4 @@
package main package tree
import ( import (
"errors" "errors"

View file

@ -1,4 +1,4 @@
package main package tree
import ( import (
"fmt" "fmt"

View file

@ -1,4 +1,4 @@
package main package tree
import ( import (
"os" "os"