Commits

Anonymous committed 18d3275

cosmetics

  • Participants
  • Parent commits 0807911

Comments (0)

Files changed (2)

File cmd/groot-ls/main.go

 		return
 	}
 	keys := dir.Keys()
-	fmt.Printf("%s%s -> #%d key(s)\n", indent, name, len(keys))
-	for _, k := range keys {
-		fmt.Printf("%sname='%s' title='%s' type=%s\n",
-			indent, k.Name(), k.Title(), k.Class())
+	nkeys := len(keys)
+	str := "|--"
+	//fmt.Printf("%s%s -> #%d key(s)\n", indent, name, len(keys))
+	for i, k := range keys {
+		if i+1 >= nkeys {
+			str = "`--"
+		}
+		fmt.Printf("%s%s '%s' title='%s' type=%s\n",
+			indent, str, k.Name(), k.Title(), k.Class())
 		if v, ok := k.Value().(*groot.Directory); ok {
 			path := append(path, k.Name())
-			inspect(v, path, indent+"  ")
+			inspect(v, path, indent+"    ")
 		}
 	}
 }

File pkg/groot/tree.go

 package groot
 
 import (
+	"fmt"
 	"reflect"
 )
 
 	branches []Branch
 }
 
+func NewTree(file *File, name, title string) (tree *Tree, err error) {
+	tree = &Tree{
+	file: file,
+	name: name,
+	title: title,
+	entries: 0,
+	branches: make([]Branch, 0),
+	}
+	return
+}
+
+func (tree *Tree) SetFile(f *File) (err error) {
+	if tree.file != nil {
+		err = fmt.Errorf("groot: cannot migrate a Tree to another file")
+		return
+	}
+	tree.file = f
+	return
+}
+
 func (tree *Tree) Class() Class {
 	panic("not implemented")
 }
 // check interfaces
 var _ Object = (*Tree)(nil)
 var _ ROOTStreamer = (*Tree)(nil)
+var _ FileSetter = (*Tree)(nil)
 
 // EOF