Documentation ¶
Overview ¶
Package zzglob implements a file path walker.
Index ¶
- func MultiGlob(ctx context.Context, patterns []*Pattern, f fs.WalkDirFunc, opts ...GlobOption) error
- type GlobOption
- type ParseOption
- func AllowAlternation(enable bool) ParseOption
- func AllowCharClass(enable bool) ParseOption
- func AllowDoubleStar(enable bool) ParseOption
- func AllowEscaping(enable bool) ParseOption
- func AllowQuestion(enable bool) ParseOption
- func AllowStar(enable bool) ParseOption
- func ExpandTilde(enable bool) ParseOption
- func WithSwapSlashes(enable bool) ParseOption
- type Pattern
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MultiGlob ¶ added in v0.0.17
func MultiGlob(ctx context.Context, patterns []*Pattern, f fs.WalkDirFunc, opts ...GlobOption) error
MultiGlob is like Pattern.Glob, but globs multiple patterns simultaneously. The main idea is to group the patterns by root to avoid multiple different calls to fs.WalkDir (reducing filesystem I/O), and then to use fs.WalkDir on each root in parallel. As a result, files can be walked globbed multiple times, but only if distinct overlapping roots appear in different input patterns. You should either make sure that the callback f is safe to call concurrently from multiple goroutines, or set GoroutineLimit to 1.
Types ¶
type GlobOption ¶ added in v0.0.6
type GlobOption = func(*globConfig)
GlobOption functions optionally alter how Glob operates.
func GoroutineLimit ¶ added in v0.0.17
func GoroutineLimit(n int) GlobOption
GoroutineLimit sets a concurrency limit for MultiGlob. By default there is no limit. MultiGlob will create at most n worker goroutines unless n <= 0.
func TranslateSlashes ¶ added in v0.0.10
func TranslateSlashes(enable bool) GlobOption
TranslateSlashes enables or disables translating to and from fs.FS paths (always with forward slashes, / ) using filepath.FromSlash. This applies to both the matching pattern and filepaths passed to the callback, and is typically required on Windows. It usually has no effect on systems where forward slash is the path separator, so it is enabled by default.
func TraverseSymlinks ¶ added in v0.0.6
func TraverseSymlinks(traverse bool) GlobOption
TraverseSymlinks enables or disables the traversal of symlinks during globbing. It is enabled by default.
func WithFilesystem ¶ added in v0.0.7
func WithFilesystem(fs fs.FS) GlobOption
WithFilesystem allows overriding the default filesystem. By default os.DirFS is used to wrap file/directory access in an `fs.FS`.
func WithTraceLogs ¶ added in v0.0.9
func WithTraceLogs(out io.Writer) GlobOption
WithTraceLogs logs debugging information for debugging Glob itself to the provided writer. Disabled by default.
type ParseOption ¶ added in v0.0.6
type ParseOption = func(*parseConfig)
ParseOption functions optionally alter how patterns are parsed.
func AllowAlternation ¶ added in v0.0.6
func AllowAlternation(enable bool) ParseOption
AllowAlternation changes how { } are parsed. If enabled, { and } delimit alternations. If disabled, { and } are treated as literals. Enabled by default.
func AllowCharClass ¶ added in v0.0.6
func AllowCharClass(enable bool) ParseOption
AllowCharClass changes how [ ] are parsed. If enabled, [ and ] denote character classes. If disabled, [ and ] are treated as literals. Enabled by default.
func AllowDoubleStar ¶ added in v0.0.6
func AllowDoubleStar(enable bool) ParseOption
AllowDoubleStar changes how ** is parsed, and applies only if AllowStar is enabled (the default). If disabled, ** is treated as two consecutive instances of * (equivalent to a single *). Enabled by default.
func AllowEscaping ¶ added in v0.0.6
func AllowEscaping(enable bool) ParseOption
AllowEscaping changes how the escape character (usually backslash - see WithSwapSlashes), is parsed. If disabled, it is treated as a literal which does not escape the next character. By default, AllowEscaping is disabled if filepath.Separator is not / (i.e. on Windows) and enabled otherwise.
func AllowQuestion ¶ added in v0.0.6
func AllowQuestion(enable bool) ParseOption
AllowQuestion changes how ? is parsed. If disabled, ? is treated as a literal. Enabled by default.
func AllowStar ¶ added in v0.0.6
func AllowStar(enable bool) ParseOption
AllowStar changes how * is parsed. If disabled, * is treated as a literal. Enabled by default.
func ExpandTilde ¶ added in v0.0.15
func ExpandTilde(enable bool) ParseOption
ExpandTilde changes how ~ is parsed. If enabled, ~ is expanded to the current user's home directory. If disabled, ~ is treated as a literal. Enabled by default.
func WithSwapSlashes ¶ added in v0.0.10
func WithSwapSlashes(enable bool) ParseOption
WithSwapSlashes changes how \ and / are interpreted. If enabled, / becomes the escape character (which can be disabled with AllowEscaping), and \ becomes the path separator (typical on Windows). Note that after parsing, the pattern internally uses / to represent the path separator (which is consistent with io/fs). To receive the correct slashes from Match or Glob, be sure to use the TranslateSlashes option. By default, WithSwapSlashes is enabled if filepath.Separator is not / (i.e. on Windows) and disabled otherwise.
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern is a parsed glob pattern.
func Parse ¶
func Parse(pattern string, opts ...ParseOption) (*Pattern, error)
Parse parses a pattern.
func (*Pattern) Glob ¶
func (p *Pattern) Glob(f fs.WalkDirFunc, opts ...GlobOption) error
Glob globs for files matching the pattern in a filesystem.