fileglob

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: MIT Imports: 10 Imported by: 3

README

GoReleaser Logo

fileglob

A file globbing library.

Release Software License GitHub Actions Codecov branch Go Report Card Go Doc

What

fileglob is a glob library that uses gobwas/glob underneath and returns only matching files or direcories, depending on the configuration. Due to this great foundation, fileglob supports:

  • Asterisk wildcards (*)
  • Super-asterisk wildcards (**)
  • Single symbol wildcards (?)
  • Character list matchers with negation and ranges ([abc], [!abc], [a-c])
  • Alternative matchers ({a,b})
  • Nested globbing ({a,[bc]})
  • Escapable wildcards (\{a\}/\* and fileglob.QuoteMeta(pattern))

By also building on top of fs.FS, a range of alternative filesystems as well as custom filesystems are supported.

Why

gobwas/glob is very well implemented: it has a lexer, compiler, and all that, which seems like a better approach than most libraries do: regex.

It doesn't have a Walk method though, and we needed it in a couple of places. So we decided to implement it ourselves, a little bit based on how mattn/go-zglob works.

Documentation

Overview

Package fileglob provides a filesystem glob API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsMatchers added in v0.3.0

func ContainsMatchers(pattern string) bool

ContainsMatchers determines whether the pattern contains any type of glob matcher. It will also return false if the pattern is an invalid expression.

func Glob

func Glob(pattern string, opts ...OptFunc) ([]string, error)

Glob returns all files that match the given pattern in the current directory. If the given pattern indicates an absolute path, it will glob from `/`. If the given pattern starts with `../`, it will resolve to its absolute path and glob from `/`.

func MatchDirectoryAsFile added in v0.4.0

func MatchDirectoryAsFile(opts *globOptions)

MatchDirectoryAsFile makes a match on a directory match its name only.

Also check MatchDirectoryIncludesContents.

func MatchDirectoryIncludesContents added in v0.4.0

func MatchDirectoryIncludesContents(opts *globOptions)

MatchDirectoryIncludesContents makes a match on a directory match all files inside it as well.

This is the default behavior.

Also check MatchDirectoryAsFile.

func MaybeRootFS added in v1.0.1

func MaybeRootFS(opts *globOptions)

MaybeRootFS setups fileglob to walk from the root directory (/) or volume (on windows) if the given pattern is an absolute path.

Result will also be prepended with the root path or volume.

func QuoteMeta

func QuoteMeta(opts *globOptions)

QuoteMeta quotes all glob pattern meta characters inside the argument text. For example, QuoteMeta for a pattern `{foo*}` sets the pattern to `\{foo\*\}`.

func ValidPattern added in v0.3.0

func ValidPattern(pattern string) error

ValidPattern determines whether a pattern is valid. It returns the parser error if the pattern is invalid and nil otherwise.

Types

type OptFunc added in v0.2.0

type OptFunc func(opts *globOptions)

OptFunc is a function that allow to customize Glob.

func WithFs

func WithFs(f fs.FS) OptFunc

WithFs allows to provide another fs.FS implementation to Glob.

func WriteOptions added in v1.0.1

func WriteOptions(w io.Writer) OptFunc

WriteOptions write the current options to the given writer.

Jump to

Keyboard shortcuts

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