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"
"fmt"
"time"
"git.lattuga.net/blallo/ruspa/tree"
)
type UnitValue struct {
@ -35,24 +37,29 @@ func (u *UnitValue) Set(value string) error {
u.unit = "PB"
return nil
default:
return ErrUnknownUnit
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()
t := NewTop(path)
if depth == 0 {
t = tree.NewSingle(path)
} else {
t = tree.NewTop(path)
}
t.SetUnit(unit.String())
go t.Spawn(depth)
go t.Collect()
for {
for !t.Complete() {
select {
case <-time.After(500 * time.Millisecond):
fmt.Printf("\033[H\033[2J")

View file

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

View file

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

View file

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

View file

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

View file

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