New upstream version 0.0~git20201026.fce18e2
Dr. Tobias Quathamer
3 years ago
0 | arch: | |
1 | - amd64 | |
2 | - ppc64le | |
3 | ||
0 | 4 | language: go |
1 | 5 | sudo: false |
2 | 6 | 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 | |
6 | 10 | - tip |
11 | matrix: | |
12 | allow_failures: | |
13 | - go: tip | |
7 | 14 | install: |
8 | 15 | - go get -t -v ./... |
9 | 16 | 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. |
6 | 6 | "os" |
7 | 7 | |
8 | 8 | "github.com/a8m/tree" |
9 | "github.com/a8m/tree/ostree" | |
9 | 10 | ) |
10 | 11 | |
11 | 12 | var ( |
80 | 81 | -C Turn colorization on always. |
81 | 82 | ` |
82 | 83 | |
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 | ||
101 | 84 | func main() { |
102 | 85 | flag.Usage = func() { fmt.Fprint(os.Stderr, usage) } |
103 | 86 | var nd, nf int |
130 | 113 | // Set options |
131 | 114 | opts := &tree.Options{ |
132 | 115 | // Required |
133 | Fs: new(fs), | |
116 | Fs: new(ostree.FS), | |
134 | 117 | OutFile: outFile, |
135 | 118 | // List |
136 | 119 | All: *a, |
4 | 4 | exit 0 |
5 | 5 | } |
6 | 6 | |
7 | failures=0 | |
7 | 8 | while read -r line; do |
8 | 9 | parts=(${line//\// }) |
9 | 10 | export GOOS=${parts[0]} |
10 | 11 | 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 | |
13 | 21 | 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 | } |