-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |