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"
|
||||
"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")
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package tree
|
||||
|
||||
import (
|
||||
"os"
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package tree
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package tree
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package tree
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package tree
|
||||
|
||||
import (
|
||||
"os"
|
Loading…
Reference in a new issue