xignore

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2019 License: MIT Imports: 11 Imported by: 15

README

Build Status GoDoc GitHub release

xignore

A golang package for pattern matching of file paths. Like gitignore, dockerignore chefignore.

Requirements

  • Golang ≥ 1.11

Use

result := xignore.DirMatches("/workspace/my_project", &MatchesOptions{
	Ignorefile: ".gitignore",
	Nested: true, // Handle nested ignorefile
})

// ignorefile rules matched files
fmt.Printf("%#v\n", result.MatchedFiles)
// ignorefile rules unmatched files
fmt.Printf("%#v\n", result.UnmatchedFiles)
// ignorefile rules matched dirs
fmt.Printf("%#v\n", result.MatchedDirs)
// ignorefile rules unmatched dirs
fmt.Printf("%#v\n", result.UnmatchedDirs)

LICENSE

MIT

Reference

Documentation

Index

Constants

View Source
const DefaultIgnorefile = ".xignore"

DefaultIgnorefile default ignorefile name ".xignore"

Variables

This section is empty.

Functions

This section is empty.

Types

type Ignorefile

type Ignorefile struct {
	Patterns []string
}

Ignorefile ignore file

func (*Ignorefile) FromReader

func (f *Ignorefile) FromReader(reader io.Reader) error

FromReader reads patterns from reader. This will trim whitespace from each line as well as use GO's "clean" func to get the shortest/cleanest path for each.

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

Matcher xignore matcher

func NewMatcher added in v0.3.1

func NewMatcher(fs afero.Fs) *Matcher

NewMatcher create matcher from custom filesystem

func NewSystemMatcher

func NewSystemMatcher() *Matcher

NewSystemMatcher create matcher for system filesystem

func (*Matcher) Matches

func (m *Matcher) Matches(basedir string, options *MatchesOptions) (*MatchesResult, error)

Matches returns matched files from dir files.

type MatchesOptions

type MatchesOptions struct {
	// Ignorefile name, similar '.gitignore', '.dockerignore', 'chefignore'
	Ignorefile string
	// Allow nested ignorefile
	Nested bool
	// apply patterns before all ignorefile
	BeforePatterns []string
	// apply patterns after all ignorefile
	AfterPatterns []string
}

MatchesOptions matches options

type MatchesResult

type MatchesResult struct {
	BaseDir string
	// ignorefile rules matched files
	MatchedFiles []string
	// ignorefile rules unmatched files
	UnmatchedFiles []string
	// ignorefile rules matched dirs
	MatchedDirs []string
	// ignorefile rules unmatched dirs
	UnmatchedDirs []string
}

MatchesResult matches result

func DirMatches

func DirMatches(basedir string, options *MatchesOptions) (*MatchesResult, error)

DirMatches returns match result from basedir.

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

Pattern defines a single regexp used used to filter file paths.

func NewPattern

func NewPattern(strPattern string) *Pattern

NewPattern create new pattern

func (*Pattern) IsEmpty

func (p *Pattern) IsEmpty() bool

IsEmpty returns true if this pattern is empty

func (*Pattern) IsExclusion

func (p *Pattern) IsExclusion() bool

IsExclusion returns true if this pattern defines exclusion

func (*Pattern) IsRoot

func (p *Pattern) IsRoot() bool

IsRoot return true if this pattern is root

func (*Pattern) Match

func (p *Pattern) Match(path string) bool

Match match path

func (*Pattern) Matches

func (p *Pattern) Matches(files []string) []string

Matches match paths

func (*Pattern) Prepare

func (p *Pattern) Prepare() error

Prepare preapre pattern

func (*Pattern) String

func (p *Pattern) String() string

Jump to

Keyboard shortcuts

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