filepath

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: MPL-2.0, MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(p *string) error

func AncestorDirs

func AncestorDirs(start, end string) (dirs []string)

AncestorDirs returns all absolute paths between a starting descendant absolute path and an ancestor absolute path.

The end path is included in the results (if it is encountered).

If the end path is not encountered, all ancestors will be returned up to the root.

func Append

func Append(paths ...string) (joined string, err error)

Append behaves like Join except that as each element must add at least one level to the path.

For example, an element with "../../some_path" would effectively replace a level instead of adding one.

An error is returned after the first illegal element is reached.

func FileAncestor

func FileAncestor(descendant, root string) (a []string, err error)

FileAncestor returns the intermediate directories between a root directory and a descendant file/directory.

For example, consider the behavior of os.MkdirAll. Just as it creates all intermediate directories as necessary to fulfill the request, this function returns the names of those directories instead of creating them. And instead of using / or the working directory as a root or starting point based on the name, this function requires the root to be chosen and applies it globally.

It will return an error if the file/directory is not a descendant of the root.

Every input and output path is resolved with filepath.Abs.

func IsGoFile

func IsGoFile(name string) bool

func PathToSafeFilename

func PathToSafeFilename(p string) string

PathToSafeFilename converts a filepath to a string usable as a filename.

func WalkAbs

func WalkAbs(root string, walkFn WalkFunc) (errs []error)

WalkAbs wraps the standard Walk to make several adjustments: an absolute path is passed to the standard Walk, absolute paths are passed to the input WalkFunc, and the WalkFunc is a new type defined by this package.

Types

type Glob

type Glob struct {
	// Pattern is a pattern to match against a candidate path.
	Pattern string

	// Root is an optional prefix prepended to Glob in case the latter is a relative path.
	Root string
}

Glob defines an inclusion pattern for GlobAny searches.

func (Glob) String

func (i Glob) String() string

type GlobAnyInput

type GlobAnyInput struct {
	// Include selects the patterns used to search for candidate paths.
	Include []Glob

	// Exclude selects patterns used to disqualify candidate paths.
	Exclude []Glob
}

GlobAnyInput defines a path-matching operation which considers whether candidate paths match at least one inclusion pattern while matching zero exclusion patterns.

type GlobAnyOutput

type GlobAnyOutput struct {
	// Include holds absolute paths indexed by the patterns that matched them.
	//
	// If multiple patterns match, the value is the first encountered.
	Include map[string]Glob

	// Exclude holds absolute paths indexed by the patterns that matched them.
	//
	// If multiple patterns match, the value is the first encountered.
	Exclude map[string]Glob
}

GlobAnyOutput describes the result of a GlobAnyInput evalation of candidate paths.

func GlobAny

func GlobAny(in GlobAnyInput) (out GlobAnyOutput, err error)

GlobAny evaluates whether candidate paths match at least one inclusion pattern while matching zero exclusion patterns.

All GlobAnyInput.Include patterns will be used to discover candidate paths. All GlobAnyInput.Include patterns will be used to disqualify every candidate path.

func (GlobAnyOutput) String

func (o GlobAnyOutput) String() (s string)

type MatchAnyInput

type MatchAnyInput struct {
	// Name is the candidate path used in evaluation against Include and Exclude globs.
	Name string

	// Include holds patterns which must match against Name.
	//
	// It can be combined with Exclude patterns.
	Include []string

	// Exclude holds patterns which cannot match against Name.
	//
	// It can be combined with Include patterns.
	Exclude []string
}

MatchAnyInput defines a path-matching operation which considers whether a single candidate path matches at least one inclusion pattern while matching zero exclusion patterns.

type MatchAnyOutput

type MatchAnyOutput struct {
	// Match is true if MatchAnyInput.Name is considered a match.
	Match bool

	// Include is the first MatchAnyInput.Include pattern that led to a match.
	Include string

	// Exclude is the first MatchAnyExput.Exclude pattern that prevented a match.
	Exclude string
}

MatchAnyOutput describes the result of a MatchAnyInput evalation of a candidate path.

func PathMatchAny

func PathMatchAny(in MatchAnyInput) (out MatchAnyOutput, err error)

PathMatchAny evaluates whether a single candidate path matches at least one inclusion pattern while matching zero exclusion patterns.

type WalkFunc

type WalkFunc func(string, os.FileInfo, error) []error

WalkFunc matches std_filepath.WalkFunc except it returns an error slice.

Jump to

Keyboard shortcuts

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