find

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: BSD-3-Clause Imports: 7 Imported by: 1

README

Build Status codecov Maintainability

find - Go package for locating files

Usage

See package examples!

cmd/ifind

$ go install github.com/gregoryv/find/cmd/ifind@latest
$ ifind --help

ifind supports emacs and vi editors when opening to specific line.

Documentation

Overview

Package find implements search funcs for finding files by name or content

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func InFile

func InFile(pattern, file string) (result *list.List, err error)

InFile opens and the file and uses InStream to find references

func InStream

func InStream(pattern string, stream io.Reader) *list.List

InStream works much like grep, finding references by the given pattern

Types

type Matcher

type Matcher interface {
	Match(path string) bool
}

func NewRegexp

func NewRegexp(ex *regexp.Regexp) Matcher

func NewShellPattern

func NewShellPattern(pattern string) Matcher

type Ref

type Ref struct {
	LineNo int
	Line   string
}

Ref points to a line in a file starting from 0

func (*Ref) String

func (ref *Ref) String() string

type Result added in v0.2.0

type Result struct {
	*list.List
}

func By

func By(m Matcher, root string) (*Result, error)

By returns a list of files whose names match

func ByName

func ByName(pattern, root string) (*Result, error)

ByName returns a list of files whose names match the shell like pattern

Example
package main

import (
	"fmt"
	"os"

	"github.com/gregoryv/find"
)

var testRoot string

func main() {
	os.Chdir(testRoot)
	result, _ := find.ByName("*.txt", ".")
	for e := result.Front(); e != nil; e = e.Next() {
		if s, ok := e.Value.(string); ok {
			fmt.Println(s)
		}
	}
}
Output:

a.txt
b.txt

func (*Result) Map added in v0.2.0

func (result *Result) Map(fn func(string))
Example
package main

import (
	"fmt"
	"os"

	"github.com/gregoryv/find"
)

var testRoot string

func main() {
	os.Chdir(testRoot)
	result, _ := find.ByName("*.txt", ".")
	echo := func(name string) {
		fmt.Println(name)
	}
	result.Map(echo)
}
Output:

a.txt
b.txt

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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