Giter Club home page Giter Club logo

dots's Introduction

Build Status

Dots

Implements the wildcard file matching in Go used by golint, go test etc.

Usage

import "github.com/mgechev/dots"

func main() {
  result, err := dots.Resolve([]string{"./fixtures/..."}, []string{"./fixtures/foo"})
  for _, f := range result {
    fmt.Println(f);
  }
}

If we suppose that we have the following directory structure:

├── README.md
├── fixtures
│   ├── bar
│   │   ├── bar1.go
│   │   └── bar2.go
│   ├── baz
│   │   ├── baz1.go
│   │   ├── baz2.go
│   │   └── baz3.go
│   └── foo
│       ├── foo1.go
│       ├── foo2.go
│       └── foo3.go
└── main.go

The result will be:

fixtures/bar/bar1.go
fixtures/bar/bar2.go
fixtures/baz/baz1.go
fixtures/baz/baz2.go
fixtures/baz/baz3.go

dots supports wildcard in both - the first and the last argument of Resolve, which means that you can ignore files based on a wildcard:

dots.Resolve([]string{"github.com/mgechev/dots"}, []string{"./..."}) // empty list
dots.Resolve([]string{"./fixtures/bar/..."}, []string{"./fixture/foo/...", "./fixtures/baz/..."}) // bar1.go, bar2.go

Preserve package structure

dots allow you to receive a slice of slices where each nested slice represents an individual package:

dots.ResolvePackages([]string{"github.com/mgechev/dots/..."}, []string{})

So we will get the result:

[
  [
    "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/bar/bar1.go",
    "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/bar/bar2.go"
  ],
  [
    "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz1.go",
    "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz2.go",
    "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz3.go"
  ],
  [
    "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo1.go",
    "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo2.go",
    "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo3.go"
  ],
  [
    "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/baz/baz1.go",
    "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/baz/baz2.go"
  ],
  [
    "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/foo1.go",
    "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/foo2.go"
  ],
  [
    "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/bar/bar1.go"
  ]
]

This method is especially useful, when you want to perform type checking over given package from the result.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.