Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Algebra8 committed Jul 22, 2022
1 parent f6b3048 commit 9dac22a
Showing 1 changed file with 102 additions and 1 deletion.
103 changes: 102 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,102 @@
# treefs
Package treefs provides functionality to print a simple graph of an fs.FS using
the template of the [`tree` command](https://en.wikipedia.org/wiki/Tree_(command)).

The version of `tree` whose graph is mimicked is tree v2.0.2 (c) 1996 - 2022 by
Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro.

To get the graph representation and metadata of an fs.FS, construct a TreeFS
and use its String method.

Consider the following directory (whose graph was generated by tree v2.0.2)

testdata
└── a
├── a1.test
├── a2.test
├── a3.test
├── b
│   ├── b1.test
│   ├── b2.test
│   ├── b3.test
│   └── d
│ └── d1.test
└── c
├── c1.test
└── c2.test

4 directories, 9 files

Its graph could be constructed using treefs in the following way

```go
var testdataFS fs.FS // assume this is embeded or read with os.DirFS
tfs, err := New(testdataFS, "testdata")
if err != nil {
log.Fatal(err)
}
fmt.Println(tfs)
```

which would generate the following output

testdata
└── a
├── a1.test
├── a2.test
├── a3.test
├── b
│ ├── b1.test
│ ├── b2.test
│ ├── b3.test
│ └── d
│ └── d1.test
└── c
├── c1.test
└── c2.test

4 directories, 9 files

Aggregated trees are allowed as well:

```go
var args []Arg // see internal/examples/multi
multitfs, err := NewMutli(args...)
if err != nil {
log.Fatal(err)
}
fmt.Println(multitfs)
```

could result in the following aggregate

.
└── main.go
../../../../treefs
├── LICENSE
├── go.mod
├── internal
│ └── examples
│ ├── multi
│ │ └── main.go
│ └── single
│ └── main.go
├── testdata
│ └── a
│ ├── a1.test
│ ├── a2.test
│ ├── a3.test
│ ├── b
│ │ ├── b1.test
│ │ ├── b2.test
│ │ ├── b3.test
│ │ └── d
│ │ └── d1.test
│ └── c
│ ├── c1.test
│ └── c2.test
├── treefs.go
└── treefs_test.go

9 directories, 16 files

See [`internal/examples`](https://github.com/Algebra8/treefs/tree/main/internal/examples) for example usage.

0 comments on commit 9dac22a

Please sign in to comment.