From 6ccb16e7bda68c4e6d8f03edb34dda0cefa7a169 Mon Sep 17 00:00:00 2001 From: Blallo Date: Thu, 5 Mar 2020 14:32:50 +0100 Subject: [PATCH] Package the logic. Create cli entrypoint. --- main.go => cmd/ru/main.go | 13 ++++++++++--- dir_utils.go => tree/dir_utils.go | 2 +- dir_utils_test.go => tree/dir_utils_test.go | 2 +- dynamic_tree.go => tree/dynamic_tree.go | 2 +- dynamic_tree_test.go => tree/dynamic_tree_test.go | 2 +- real_walker.go => tree/real_walker.go | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) rename main.go => cmd/ru/main.go (83%) rename dir_utils.go => tree/dir_utils.go (96%) rename dir_utils_test.go => tree/dir_utils_test.go (99%) rename dynamic_tree.go => tree/dynamic_tree.go (99%) rename dynamic_tree_test.go => tree/dynamic_tree_test.go (99%) rename real_walker.go => tree/real_walker.go (97%) diff --git a/main.go b/cmd/ru/main.go similarity index 83% rename from main.go rename to cmd/ru/main.go index caed381..33e07d5 100644 --- a/main.go +++ b/cmd/ru/main.go @@ -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") diff --git a/dir_utils.go b/tree/dir_utils.go similarity index 96% rename from dir_utils.go rename to tree/dir_utils.go index cffa3e4..5d55df4 100644 --- a/dir_utils.go +++ b/tree/dir_utils.go @@ -1,4 +1,4 @@ -package main +package tree import ( "os" diff --git a/dir_utils_test.go b/tree/dir_utils_test.go similarity index 99% rename from dir_utils_test.go rename to tree/dir_utils_test.go index e6ade64..0c77a90 100644 --- a/dir_utils_test.go +++ b/tree/dir_utils_test.go @@ -1,4 +1,4 @@ -package main +package tree import ( "io/ioutil" diff --git a/dynamic_tree.go b/tree/dynamic_tree.go similarity index 99% rename from dynamic_tree.go rename to tree/dynamic_tree.go index fc21289..5de1dee 100644 --- a/dynamic_tree.go +++ b/tree/dynamic_tree.go @@ -1,4 +1,4 @@ -package main +package tree import ( "errors" diff --git a/dynamic_tree_test.go b/tree/dynamic_tree_test.go similarity index 99% rename from dynamic_tree_test.go rename to tree/dynamic_tree_test.go index 6cc16a0..4721770 100644 --- a/dynamic_tree_test.go +++ b/tree/dynamic_tree_test.go @@ -1,4 +1,4 @@ -package main +package tree import ( "fmt" diff --git a/real_walker.go b/tree/real_walker.go similarity index 97% rename from real_walker.go rename to tree/real_walker.go index e991d15..edcd8fc 100644 --- a/real_walker.go +++ b/tree/real_walker.go @@ -1,4 +1,4 @@ -package main +package tree import ( "os"