Debian Codegraph @

README.md

raw symbols SCIP
1 # Dots
2
3 [![Build Status](https://github.com/mgechev/dots/actions/workflows/pr.yaml/badge.svg)](https://github.com/mgechev/dots/actions/workflows/pr.yaml)
4 [![Go Reference](https://pkg.go.dev/badge/github.com/mgechev/dots.svg)](https://pkg.go.dev/github.com/mgechev/dots)
5
6 `dots` is a Go package that provides advanced wildcard file and package matching, similar to the behavior used by tools like `go test` and `golint`.
7 It allows you to easily resolve file paths and packages using patterns with `...` wildcards, and supports flexible exclusion rules.
8
9 ## Usage
10
11 ```go
12 import (
13 "fmt"
14
15 "github.com/mgechev/dots"
16 )
17
18 func main() {
19 result, err := dots.Resolve([]string{"./fixtures/..."}, []string{"./fixtures/foo"})
20 for _, f := range result {
21 fmt.Println(f);
22 }
23 }
24 ```
25
26 If we suppose that we have the following directory structure:
27
28 ```text
29 ├── README.md
30 ├── fixtures
31 │   ├── bar
32 │   │   ├── bar1.go
33 │   │   └── bar2.go
34 │   ├── baz
35 │   │   ├── baz1.go
36 │   │   ├── baz2.go
37 │   │   └── baz3.go
38 │   └── foo
39 │   ├── foo1.go
40 │   ├── foo2.go
41 │   └── foo3.go
42 └── main.go
43 ```
44
45 The result will be:
46
47 ```text
48 fixtures/bar/bar1.go
49 fixtures/bar/bar2.go
50 fixtures/baz/baz1.go
51 fixtures/baz/baz2.go
52 fixtures/baz/baz3.go
53 ```
54
55 `dots` supports wildcard in both - the first and the last argument of `Resolve`, which means that you can ignore files based on a wildcard:
56
57 ```go
58 dots.Resolve([]string{"github.com/mgechev/dots"}, []string{"./..."}) // empty list
59 dots.Resolve([]string{"./fixtures/bar/..."}, []string{"./fixture/foo/...", "./fixtures/baz/..."}) // bar1.go, bar2.go
60 ```
61
62 ## Preserve package structure
63
64 `dots` allow you to receive a slice of slices where each nested slice represents an individual package:
65
66 ```go
67 dots.ResolvePackages([]string{"github.com/mgechev/dots/..."}, []string{})
68 ```
69
70 So we will get the result:
71
72 ```text
73 [
74 [
75 "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/bar/bar1.go",
76 "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/bar/bar2.go"
77 ],
78 [
79 "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz1.go",
80 "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz2.go",
81 "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz3.go"
82 ],
83 [
84 "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo1.go",
85 "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo2.go",
86 "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo3.go"
87 ],
88 [
89 "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/baz/baz1.go",
90 "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/baz/baz2.go"
91 ],
92 [
93 "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/foo1.go",
94 "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/foo2.go"
95 ],
96 [
97 "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/bar/bar1.go"
98 ]
99 ]
100 ```
101
102 This method is especially useful, when you want to perform type checking over given package from the result.