Codebase list golang-github-a8m-tree / ec3598d
New upstream version 0.0~git20201026.fce18e2 Dr. Tobias Quathamer 3 years ago
8 changed file(s) with 110 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
0 arch:
1 - amd64
2 - ppc64le
3
04 language: go
15 sudo: false
26 go:
3 - 1.6.4
4 - 1.7.4
5 - 1.8.3
7 - 1.13.x
8 - 1.14.x
9 - 1.15.x
610 - tip
11 matrix:
12 allow_failures:
13 - go: tip
714 install:
815 - go get -t -v ./...
916 script:
0 MIT License
1
2 Copyright (c) 2015-2017 Ariel Mashraki
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
66 "os"
77
88 "github.com/a8m/tree"
9 "github.com/a8m/tree/ostree"
910 )
1011
1112 var (
8081 -C Turn colorization on always.
8182 `
8283
83 type fs struct{}
84
85 func (f *fs) Stat(path string) (os.FileInfo, error) {
86 return os.Lstat(path)
87 }
88 func (f *fs) ReadDir(path string) ([]string, error) {
89 dir, err := os.Open(path)
90 if err != nil {
91 return nil, err
92 }
93 names, err := dir.Readdirnames(-1)
94 dir.Close()
95 if err != nil {
96 return nil, err
97 }
98 return names, nil
99 }
100
10184 func main() {
10285 flag.Usage = func() { fmt.Fprint(os.Stderr, usage) }
10386 var nd, nf int
130113 // Set options
131114 opts := &tree.Options{
132115 // Required
133 Fs: new(fs),
116 Fs: new(ostree.FS),
134117 OutFile: outFile,
135118 // List
136119 All: *a,
44 exit 0
55 }
66
7 failures=0
78 while read -r line; do
89 parts=(${line//\// })
910 export GOOS=${parts[0]}
1011 export GOARCH=${parts[1]}
11 echo Try GOOS=${GOOS} GOARCH=${GOARCH}
12 go install
12 if go tool compile -V >/dev/null 2>&1 ; then
13 echo Try GOOS=${GOOS} GOARCH=${GOARCH}
14 if ! go install; then
15 echo "*** Failed compiling GOOS=${GOOS} GOARCH=${GOARCH}"
16 failures=$((failures+1))
17 fi
18 else
19 echo Skipping GOOS=${GOOS} GOARCH=${GOARCH} as not supported
20 fi
1321 done < <(go tool dist list)
22
23 if [ $failures -ne 0 ]; then
24 echo "*** $failures compile failures"
25 exit 1
26 fi
0 package ostree
1
2 import (
3 "bytes"
4 "os"
5
6 "github.com/a8m/tree"
7 )
8
9 // FS uses the system filesystem
10 type FS struct{}
11
12 // Stat a path
13 func (f *FS) Stat(path string) (os.FileInfo, error) {
14 return os.Lstat(path)
15 }
16
17 // ReadDir reads a directory
18 func (f *FS) ReadDir(path string) ([]string, error) {
19 dir, err := os.Open(path)
20 if err != nil {
21 return nil, err
22 }
23 names, err := dir.Readdirnames(-1)
24 dir.Close()
25 if err != nil {
26 return nil, err
27 }
28 return names, nil
29 }
30
31 // Print a tree of the directory
32 func Print(dir string) string {
33 b := new(bytes.Buffer)
34 tr := tree.New(dir)
35 opts := &tree.Options{
36 Fs: new(FS),
37 OutFile: b,
38 }
39 tr.Visit(opts)
40 tr.Print(opts)
41 return b.String()
42 }
0 package ostree
1
2 import (
3 "testing"
4 )
5
6 func TestTree(t *testing.T) {
7 actual := Print("testdata")
8 expect := `testdata
9 ├── a
10 │ └── b
11 │ └── b.txt
12 └── c
13 └── c.txt
14 `
15 if actual != expect {
16 t.Errorf("\nactual\n%s\n != expect\n%s\n", actual, expect)
17 }
18 }
(New empty file)
(New empty file)