Package the logic. Create cli entrypoint.
This commit is contained in:
parent
ce417a1df6
commit
6ccb16e7bd
6 changed files with 15 additions and 8 deletions
|
@ -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")
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package tree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package tree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package tree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package tree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package tree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
Loading…
Reference in a new issue