glob

package module
v0.0.0-...-0de2b7f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2022 License: GPL-3.0 Imports: 11 Imported by: 1

README

glob

Main codecov

Usage

The most simple form would be by just providing a glob pattern

files, err := glob.Glob(glob.Pattern("**/*.txt"))

You can pass additionally to a pattern multiple options like IgnoreFiles. The Ignore files will parse the provided files according to the Git Ignore Spec and will ignore the directories or files.

files, err := glob.Glob(glob.Pattern("**/*"), glob.IgnoreFile(".gitignore"))

The Ign

Advanced configuration use case:

files, err := glob.Glob(&glob.Options{
  Patterns:       []string{"**/*.txt"},
  CWD:            "/some/abs/path",
  IgnorePatterns: []string{"node_modules", "other/*.file"},
})

Installation

go get -u github.com/lukasholzer/go-glob

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Glob

func Glob(options ...*Options) ([]string, error)

Glob is the main glob function that is used to get a list of files in a specific directory matching the patterns and respecting the ignores

func Match

func Match(p *ParsedPattern, path string) bool

Types

type GlobPatterns

type GlobPatterns = map[string]*ParsedPattern

func ParseGitignore

func ParseGitignore(file string) (GlobPatterns, error)

func ParseGitignoreContent

func ParseGitignoreContent(content string) (GlobPatterns, error)

ParseGitignoreContent parses a file according to: http://git-scm.com/docs/gitignore

type Options

type Options struct {
	IgnorePatterns []string
	IgnoreFiles    []string
	CWD            string
	Patterns       []string
	AbsolutePaths  bool
	Debug          bool
}

func CWD

func CWD(cwd string) *Options

CWD sets a cwd where the glob pattern is executed in by default the process current working directory is used

func IgnoreFile

func IgnoreFile(files string) *Options

IgnoreFiles provides a list on file paths relative to the current working directory that follow the .gitignore syntax and are used to provide ignore patterns

func IgnorePattern

func IgnorePattern(pattern string) *Options

IgnorePatterns sets a list of patterns that is used for ignoring specific files or directories

func Pattern

func Pattern(pattern string) *Options

type ParsedPattern

type ParsedPattern struct {

	// input is the original glob pattern
	Input      string
	RegExp     *regexp.Regexp
	IsGlobstar bool
	// base is the base folder that can be used for matching a glob.
	// For example if a glob starts with `src/**/*.ts` we don't need to crawl all
	// folders in the current working directory as we see the `src` as base folder
	Base string
	// contains filtered or unexported fields
}

func Parse

func Parse(input string) (*ParsedPattern, error)

func (*ParsedPattern) Compile

func (p *ParsedPattern) Compile() (*ParsedPattern, error)

func (*ParsedPattern) String

func (p *ParsedPattern) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL