ignore

package
v0.0.0-...-c29b7ad Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ignore provides tools for writing ignore files (a la .gitignore).

This provides both an ignore parser and a file-aware processor.

The format of ignore files closely follows, but does not exactly match, the format for .gitignore files (https://git-scm.com/docs/gitignore).

The formatting rules are as follows:

  • Parsing is line-by-line
  • Empty lines are ignored
  • Lines the begin with # (comments) will be ignored
  • Leading and trailing spaces are always ignored
  • Inline comments are NOT supported ('foo* # Any foo' does not contain a comment)
  • There is no support for multi-line patterns
  • Shell glob patterns are supported. See Go's "path/filepath".Match
  • If a pattern begins with a leading !, the match will be negated.
  • If a pattern begins with a leading /, only paths relatively rooted will match.
  • If the pattern ends with a trailing /, only directories will match
  • If a pattern contains no slashes, file basenames are tested (not paths)
  • The pattern sequence "**", while legal in a glob, will cause an error here (to indicate incompatibility with .gitignore).

Example:

# Match any file named foo.txt
foo.txt

# Match any text file
*.txt

# Match only directories named mydir
mydir/

# Match only text files in the top-level directory
/*.txt

# Match only the file foo.txt in the top-level directory
/foo.txt

# Match any file named ab.txt, ac.txt, or ad.txt
a[b-d].txt

Notable differences from .gitignore:

  • The '**' syntax is not supported.
  • The globbing library is Go's 'filepath.Match', not fnmatch(3)
  • Trailing spaces are always ignored (there is no supported escape sequence)
  • The evaluation of escape sequences has not been tested for compatibility
  • There is no support for '\!' as a special leading sequence.

Index

Constants

View Source
const HelmIgnore = ".helmignore"

HelmIgnore default name of an ignorefile.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rules

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

Rules is a collection of path matching rules.

Parse() and ParseFile() will construct and populate new Rules. Empty() will create an immutable empty ruleset.

func Empty

func Empty() *Rules

Empty builds an empty ruleset.

func Parse

func Parse(file io.Reader) (*Rules, error)

Parse parses a rules file

func ParseFile

func ParseFile(file string) (*Rules, error)

ParseFile parses a helmignore file and returns the *Rules.

func (*Rules) AddDefaults

func (r *Rules) AddDefaults()

AddDefaults adds default ignore patterns.

Ignore all dotfiles in "templates/"

func (*Rules) Ignore

func (r *Rules) Ignore(path string, fi os.FileInfo) bool

Ignore evalutes the file at the given path, and returns true if it should be ignored.

Ignore evaluates path against the rules in order. Evaluation stops when a match is found. Matching a negative rule will stop evaluation.

func (*Rules) Len

func (r *Rules) Len() int

Len returns the number of patterns in this rule set.

Jump to

Keyboard shortcuts

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