findregex

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2021 License: MIT Imports: 8 Imported by: 0

README

findregex

findregex is a package that allows you to find regular expressions within files in a fast and efficient manner. This is tested against long directories, along with many nested subdirectories.

CLI Installation

Go to releases and download the correct binary for your platform, and put the binary somewhere in your PATH (ie in /usr/bin)

Install from source

  1. Install Go
  2. add $GOBIN to your $PATH
  3. go get github.com/deanveloper/findregex/findregex
  4. you are ready to Go :)

Use as a library

This is not only a CLI, but a library! To use it as a library, simply run go get github.com/deanveloper/findregex, and you can use it as normal. You can view documentation on https://pkg.go.dev/github.com/deanveloper/findregex

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Workers = 5

Workers is the number of workers that Search will use when reading files.

Functions

func FindFiles

func FindFiles(path string, filter FilePathFilterer) <-chan string

FindFiles takes a path and returns a string of all files that match the search params

func Search(path string, filter FilePathFilterer, matcher LineMatcher) <-chan SearchResult

Search is a combination call to FindFiles and SearchFiles, noteworthy that this function will create several workers for SearchFiles.

func SearchFiles

func SearchFiles(files <-chan string, matcher LineMatcher) <-chan SearchResult

SearchFiles takes a channel of paths, and searches for the regex in each file for the path.

Types

type FileFilterer

type FileFilterer interface {
	FilterFile(path string) bool
}

FileFilterer is an interface that determines if a file should be included or not.

type FilePathFilterer

type FilePathFilterer interface {
	PathFilterer
	FileFilterer
}

FilePathFilterer is an interface that determines if a paths and files should be included.

type GlobInclExclFilter

type GlobInclExclFilter struct {
	IncludedFiles []string
	ExcludedPaths []string
}

GlobInclExclFilter is a filter that uses glob strings to include files matched by IncludedFiles, and prune paths matched by ExcludedPaths.

func (GlobInclExclFilter) FilterFile

func (f GlobInclExclFilter) FilterFile(path string) bool

func (GlobInclExclFilter) FilterPath

func (f GlobInclExclFilter) FilterPath(path string) bool

type LineMatcher

type LineMatcher interface {
	Match(line string) bool
}

LineMatcher is an interface that checks if a line should be included.

type PathFilterer

type PathFilterer interface {
	FilterPath(path string) bool
}

PathFilterer is an interface that determines if a path should be searched or skipped.

type RegexInclExclFilter

type RegexInclExclFilter struct {
	IncludedFiles *regexp.Regexp
	ExcludedPaths *regexp.Regexp
}

RegexInclExclFilter is a filter that uses regular expressions to include files matched by IncludedFiles, and prune paths matched by ExcludedPaths.

func (RegexInclExclFilter) FilterFile

func (f RegexInclExclFilter) FilterFile(path string) bool

func (RegexInclExclFilter) FilterPath

func (f RegexInclExclFilter) FilterPath(path string) bool

type RegexpLineMatcher

type RegexpLineMatcher regexp.Regexp

func (*RegexpLineMatcher) Match

func (m *RegexpLineMatcher) Match(line string) bool

type SearchResult

type SearchResult struct {
	Path string

	LineText   string
	LineNumber int

	Err error
}

SearchResult is a simple struct containing information about a line found by SearchFiles.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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