github.com/anishathalye/periscope@v0.3.5/internal/periscope/tree.go (about) 1 package periscope 2 3 import ( 4 "github.com/anishathalye/periscope/internal/herror" 5 6 "fmt" 7 "text/tabwriter" 8 ) 9 10 type TreeOptions struct { 11 All bool 12 } 13 14 func (ps *Periscope) Tree(root string, options *TreeOptions) herror.Interface { 15 absRoot, _, err := ps.checkFile(root, false, true, "show", false, true) 16 if err != nil { 17 return err 18 } 19 w := tabwriter.NewWriter(ps.outStream, 0, 0, 1, ' ', tabwriter.DiscardEmptyColumns) 20 r, herr := ps.db.LookupAll(absRoot, options.All) 21 if herr != nil { 22 return herr 23 } 24 for _, dupe := range r { 25 _, _, err := ps.checkFile(dupe.Path, true, false, "", true, false) 26 if err != nil { 27 // something has changed 28 continue 29 } 30 showPath := relPath(absRoot, dupe.Path) 31 fmt.Fprintf(w, "%d\v%s\n", dupe.Count-1, showPath) 32 } 33 w.Flush() 34 return nil 35 }