find

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultExtensions is a predefined slice of strings containing common file
	// extensions (such as ".go" and ".ts") used as default values when searching
	// for files using the Options struct.
	DefaultExtensions = []string{
		".go",
		".ts",
	}

	DefaultExclude = []string{
		"**/.*/**",
		"**/dist/**",
		"**/node_modules/**",
		"**/vendor/**",
		"**/testdata/**",
		"**/test/**",
		"**/tests/**",
	}

	Default = Options{
		Extensions: DefaultExtensions,
		Exclude:    DefaultExclude,
	}
)

Functions

func Files added in v0.0.4

func Files(ctx context.Context, files fs.FS, opts ...Option) ([]string, error)

Files returns a list of file paths from the provided fs.FS, filtered based on the given options. The options can include or exclude files based on file extensions, and include or exclude patterns. The function also supports context cancellation.

Types

type Option

type Option func(*Options)

Option is a functional option type that allows customization of the behavior of the Options struct, which is used in the file search process. It can be used to modify extensions, include or exclude specific patterns, and other search-related configurations.

func Exclude

func Exclude(patterns ...string) Option

Exclude appends the given patterns to the Options.Exclude field, marking them to be excluded from the file search. The function returns an Option for use with the Files function.

func Extensions added in v0.0.4

func Extensions(exts ...string) Option

Extensions returns an Option that sets the allowed file extensions for the Options struct. The given exts parameter is a list of strings representing the desired file extensions.

func Include added in v0.0.4

func Include(patterns ...string) Option

Include adds the given patterns to the list of include patterns for file search, allowing the inclusion of matching files in the search results.

type Options added in v0.0.4

type Options struct {
	Extensions []string
	Include    []string
	Exclude    []string
}

Options is a configuration struct that defines the filtering rules for file searching, such as file extensions to include, patterns to include or exclude. It provides methods for determining if a given file path is included or excluded based on these rules.

func (Options) Find added in v0.0.4

func (f Options) Find(ctx context.Context, files fs.FS) ([]string, error)

Find searches the provided file system (fs.FS) using the options specified, such as extensions, include and exclude patterns, and returns a slice of file paths matching the criteria. It also respects the context (context.Context) for cancellation or timeouts.

Jump to

Keyboard shortcuts

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