files

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

File tools that read, write, edit, glob and grep inside an optional root

Index

Constants

View Source
const (
	ReadName  = "Read"
	WriteName = "Write"
	EditName  = "Edit"
	GlobName  = "Glob"
	GrepName  = "Grep"
)
View Source
const OutlineName = "Outline"

Variables

This section is empty.

Functions

func All

func All(o Options) []tool.Tool

Every file tool sharing one set of options

func Edit

func Edit(o Options) tool.Tool

Tool that replaces exact text in a file and shows the edited region back

func Glob

func Glob(o Options) tool.Tool

Tool that lists files and directories matching a pattern, newest first

func Grep

func Grep(o Options) tool.Tool

Tool that searches file contents with a regular expression

func Outline

func Outline(o Options) tool.Tool

Tool that lists definition lines of a file or tree with line numbers

func Read

func Read(o Options) tool.Tool

Tool that returns numbered lines of a text file or the bytes of an image

func Write

func Write(o Options) tool.Tool

Tool that replaces a whole file atomically, creating parents and keeping the mode

Types

type Change

type Change struct {
	Path     string
	Old      string
	New      string
	Created  bool
	Replaced int
}

Content replaced by Write or Edit, with the whole file before and after

type FileHits

type FileHits struct {
	Path    string
	ModTime time.Time
	Count   int
	Hits    []Hit
}

Matches found in one file

type GlobData

type GlobData struct {
	Dir     string
	Pattern string
	Matches []Match
	Total   int
}

Structured outcome of Glob

type GrepData

type GrepData struct {
	Pattern string
	Mode    string
	Files   []FileHits
	// Matches across every file in the requested mode
	Total int
	// Files skipped because they could not be read
	Skipped int
	// Files skipped because they were too large to match as a whole
	Oversize int
}

Structured outcome of Grep

type Hit

type Hit struct {
	Line    int
	Text    string
	Context bool
}

One matching or context line

type Match

type Match struct {
	Path    string
	Dir     bool
	ModTime time.Time
}

One path found by Glob

type Options

type Options struct {
	// Directory relative paths resolve against, the process working directory when empty
	Dir string
}

Shared settings of every file tool

func (Options) Resolve

func (o Options) Resolve(p string) (string, error)

Turns a user path into a clean absolute path

type OutlineData

type OutlineData struct {
	Path    string
	Files   int
	Symbols int
	// Files passed over for having no rule or being binary
	Skipped int
}

Structured outcome of Outline

type ReadData

type ReadData struct {
	Path string
	// First line number returned
	Offset int
	Lines  []string
	// Lines in the whole file
	Total int
	// Media type when the file was returned as an image
	MediaType string
	Bytes     int64
}

Structured outcome of Read

type ReadMany

type ReadMany struct {
	Files []ReadData
	// Paths left unread once the batch budget was spent
	Skipped []string
}

Structured outcome of a Read over several files

Jump to

Keyboard shortcuts

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