Documentation
¶
Overview ¶
Package ripgo provides a high-level API for searching files.
It orchestrates traversal (walk), filtering (ignore), and pattern matching (pattern) into a simple, unified interface for library consumers.
Basic Usage ¶
The primary entry point is the Search function, which returns an iterator of results:
ctx := context.Background()
results := ripgo.Search(ctx, "TODO", []string{"."}, ripgo.WithIgnoreCase(true))
for res, err := range results {
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
continue
}
fmt.Printf("%s: %d matches\n", res.Path, len(res.Matches))
}
Functional Options ¶
Search can be configured using functional options:
- WithMultiline(true): Enable multiline matching across line boundaries.
- WithWordRegexp(true): Match whole words only.
- WithContext(before, after): Include context lines around matches.
- WithReplace("template"): Perform string replacement using capture groups.
- WithPcre2(true): Use the PCRE2 regex engine instead of Go's default.
Filesystem Abstraction ¶
ripgo works with any io/fs.FS implementation via the WithFS option. This allows searching in-memory files, zip archives, or remote storage:
myFS := fstest.MapFS{...}
results := ripgo.Search(ctx, "pattern", []string{"."}, ripgo.WithFS(myFS))
Architecture ¶
The project is divided into several focused packages:
- github.com/nijaru/ripgo/search: File scanning and match reporting.
- github.com/nijaru/ripgo/pattern: Multi-engine pattern matching (Literal, Regex, PCRE2).
- github.com/nijaru/ripgo/walk: Parallel directory traversal.
- github.com/nijaru/ripgo/ignore: Gitignore-compatible filtering logic.
Package ripgo provides a high-level API for searching files.
It orchestrates the walk, ignore, pattern, and search packages into a simple, unified interface for library consumers.
Index ¶
- func Search(ctx context.Context, patternStr string, paths []string, opts ...Option) iter.Seq2[search.Result, error]
- type Config
- type Option
- func WithContext(before, after int) Option
- func WithFS(fsys fs.FS) Option
- func WithFixedStrings(v bool) Option
- func WithFollowSymlinks(v bool) Option
- func WithGlobExcludes(globs ...string) Option
- func WithGlobIncludes(globs ...string) Option
- func WithHidden(v bool) Option
- func WithIgnoreCase(v bool) Option
- func WithMatcher(m pattern.Matcher) Option
- func WithMaxCount(n int) Option
- func WithMaxFileSize(n int64) Option
- func WithMultiline(v bool) Option
- func WithNoIgnore(v bool) Option
- func WithOnlyMatching(v bool) Option
- func WithPcre2(v bool) Option
- func WithReplace(v string) Option
- func WithThreads(n int) Option
- func WithTypes(types []string) Option
- func WithTypesNot(typesNot []string) Option
- func WithWordRegexp(v bool) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Search ¶
func Search(ctx context.Context, patternStr string, paths []string, opts ...Option) iter.Seq2[search.Result, error]
Search performs a complete search using the provided configuration and paths. It returns an iterator of (Result, error). The error is non-nil if a file-level error was encountered (e.g. Permission Denied).
Types ¶
type Config ¶
type Config struct {
Pattern pattern.Config
Search search.Config
Walk walk.Config
Ignore ignore.Config
FS fs.FS
Matcher pattern.Matcher
}
Config represents the complete search configuration.
func DefaultConfig ¶
DefaultConfig returns a configuration with sensible defaults.
type Option ¶
type Option func(*Config)
Option is a functional option for configuring the search.
func WithContext ¶
func WithFixedStrings ¶
func WithFollowSymlinks ¶
func WithGlobExcludes ¶
func WithGlobIncludes ¶
func WithHidden ¶
func WithIgnoreCase ¶
func WithMatcher ¶
func WithMaxCount ¶
func WithMaxFileSize ¶
func WithMultiline ¶
func WithNoIgnore ¶
func WithOnlyMatching ¶
func WithReplace ¶
func WithThreads ¶
func WithTypesNot ¶
func WithWordRegexp ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
ripgo
command
|
|
|
Package ignore implements gitignore-compatible file filtering.
|
Package ignore implements gitignore-compatible file filtering. |
|
internal
|
|
|
aho
Package aho implements a minimal Aho-Corasick automaton for multi-literal pre-filtering.
|
Package aho implements a minimal Aho-Corasick automaton for multi-literal pre-filtering. |
|
osfs
Package osfs provides an fs.FS implementation for the local OS filesystem.
|
Package osfs provides an fs.FS implementation for the local OS filesystem. |
|
Package printer implements various output formats for search results.
|
Package printer implements various output formats for search results. |
|
Package stats provides search statistics tracking.
|
Package stats provides search statistics tracking. |
|
Package walk implements parallel directory traversal.
|
Package walk implements parallel directory traversal. |