path

package
v0.0.0-...-e537141 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: GPL-3.0 Imports: 9 Imported by: 1

Documentation

Overview

Package path provides simple abstractions over the os/path package of the go standard library. It should be used in conjunction with the shutil/fs package

Index

Constants

This section is empty.

Variables

View Source
var DefaultPathKinds = PathKinds{
	"glob": PathPattern,
	"file": PathFile,
}
View Source
var ErrExtensionMissing = fmt.Errorf("path/filter.go: extension could not be determined or empty")

Functions

func GatherAll

func GatherAll(dirPath string) (paths []string, err error)

func IsType

func IsType(l Like, t Type) (b bool)

func MustBeType

func MustBeType(l Like, t Type) (err error)

Types

type Dir

type Dir struct {
	// contains filtered or unexported fields
}

func NewDir

func NewDir(s string) (d Dir)

func (Dir) ExpectedType

func (d Dir) ExpectedType() (t Type)

func (Dir) PathString

func (d Dir) PathString() (s string)

func (*Dir) Set

func (d *Dir) Set(s string) (err error)

type ErrDuringOp

type ErrDuringOp struct {
	// Path that was under operation.
	Path Like
	// The kind of operation that was carried out.
	Op Operation
	// contains filtered or unexported fields
}

ErrDuringOp wraps and error that happened during an operation.

func OpError

func OpError(like Like, op OpKind, err error) (e ErrDuringOp)

OpError is convenience function for generating an ErrDuringOp struct.

func (ErrDuringOp) Error

func (e ErrDuringOp) Error() (s string)

func (ErrDuringOp) Unwrap

func (e ErrDuringOp) Unwrap() (err error)

type Extension

type Extension struct {
	// contains filtered or unexported fields
}

func GetExtension

func GetExtension(s Stringer) (ext Extension, b bool)

func MustGetExtension

func MustGetExtension(s Stringer) (ext Extension, err error)

func NewExtension

func NewExtension(ext string) (ex Extension)

func (Extension) String

func (e Extension) String() (s string)

type Extensions

type Extensions struct {
	Extensions    mapping.StringSet
	Mode          filter.SelectMode
	HandleMissing MissingExtHandling
}

func (Extensions) ToFilter

func (e Extensions) ToFilter(l zerolog.Logger) (se SelectedExtensions)

type File

type File struct {
	// contains filtered or unexported fields
}

func NewFile

func NewFile(s string) (f File)

func (File) ExpectedType

func (f File) ExpectedType() (t Type)

func (File) PathString

func (f File) PathString() (s string)

func (*File) Set

func (f *File) Set(s string) (err error)

type Filter

type Filter interface {
	FilterPaths(b []bool, p []string) (err error)
}

type GatherPaths

type GatherPaths struct {
	// contains filtered or unexported fields
}

func NewPathGatherer

func NewPathGatherer(fsys fs.FS, l zerolog.Logger) (g GatherPaths)

func (GatherPaths) GatherPatterns

func (g GatherPaths) GatherPatterns(p Patterns) (outPaths Paths, err error)

func (GatherPaths) GetPaths

func (g GatherPaths) GetPaths() (p []string)

func (*GatherPaths) PatternVisitor

func (g *GatherPaths) PatternVisitor(prefix *string, path string, kind PatternKind) (err error)

func (GatherPaths) VisitPattern

func (g GatherPaths) VisitPattern(path string, kind PatternKind) (paths []string, err error)

type Glob

type Glob struct {
	Parts []string
}

func NewGlob

func NewGlob(parts ...string) (g Glob)

func (Glob) ListPaths

func (g Glob) ListPaths() (paths []string, err error)

func (*Glob) SetRoot

func (g *Glob) SetRoot(root string)

type GlobMethods

type GlobMethods interface {
	Glob(pattern string) (matches []string, err error)
	Match(pattern, name string) (matched bool, err error)
}

type InvalidPath

type InvalidPath struct {
	// The invalid Path.
	Path Stringer
}

InvalidPath is returned from ToValid of Path is not valid.

func (InvalidPath) Error

func (i InvalidPath) Error() (s string)

type Like

type Like interface {
	Stringer
	ExpectedType() Type
}

type ListMode

type ListMode int
const (
	ListGlob ListMode = iota
	ListPath
)

func (ListMode) MarshalText

func (l ListMode) MarshalText() (s string)

func (ListMode) String

func (l ListMode) String() (s string)

func (*ListMode) UnmarshalText

func (l *ListMode) UnmarshalText(b []byte) (err error)

type Logger

type Logger zerolog.Logger

type Methods

type Methods interface {
	UnaryMethods
	WalkMethods
	GlobMethods
	SplitMethods

	Join(parts ...string) string

	IsAbs(path string) bool
	HasPrefix(p, prefix string) bool

	Rel(basepath, targpath string) (string, error)
}

type MismatchedType

type MismatchedType struct {
	Expected, Got Type
}

func (MismatchedType) Error

func (m MismatchedType) Error() (s string)

type MissingExtHandling

type MissingExtHandling int
const (
	MissingExtSkip MissingExtHandling = iota
	MissingExtError
)

type MissingExtension

type MissingExtension struct {
	PathString Stringer
}

func (MissingExtension) Error

func (m MissingExtension) Error() (s string)

type OpKind

type OpKind int

OpKind denotes different operations being carried out on paths, files, directories

const (
	// CheckValidPath represents the operation for checking if a given
	// path represents a path to an existing file or directory.
	CheckValidPath OpKind = iota
)

func (OpKind) PathDescribe

func (o OpKind) PathDescribe(l Like) (s string)

PathDescribe provides an explanitory message.

type Operation

type Operation interface {
	// PathDescribe returns an explanatory message formatted using Path.
	PathDescribe(Like) string
}

Operation represents a fallibe operation tha can be carried out on a filepath.

type PathKinds

type PathKinds map[string]PatternKind

type PathLister

type PathLister interface {
	ListPaths() (paths []string, err error)
}

type Paths

type Paths map[string][]string

type Pattern

type Pattern struct {
	Extensions *[]string `json:"extensions" toml:"extensions"`
	Path       string    `json:"path" toml:"path"`
	Mode       ListMode  `json:"mode" toml:"mode"`
}

func (Pattern) ToLister

func (p Pattern) ToLister(l zerolog.Logger) (pl PatternLister)

type PatternKind

type PatternKind int
const (
	PathPattern PatternKind = iota
	PathFile
)

type PatternLister

type PatternLister struct {
	// contains filtered or unexported fields
}

func (PatternLister) ListPaths

func (pl PatternLister) ListPaths() (paths []string, err error)

type PatternMap

type PatternMap map[string]string

func (PatternMap) ToPatterns

func (pm PatternMap) ToPatterns(fsys fs.FS, parser PatternsParser) (p Patterns, err error)

type Patterns

type Patterns struct {
	// contains filtered or unexported fields
}

func (Patterns) Visit

func (p Patterns) Visit(fn Visitor) (err error)

type PatternsConfig

type PatternsConfig struct {
	PathKinds PathKinds
	Separator string
}

func NewPatternsConfig

func NewPatternsConfig(sep string) (p PatternsConfig)

func (PatternsConfig) ParsePattern

func (pc PatternsConfig) ParsePattern(fsys fs.FS, patternLine string) (s string, k PatternKind, err error)

type PatternsParser

type PatternsParser interface {
	ParsePattern(fsys fs.FS, patternLine string) (string, PatternKind, error)
}

type Raw

type Raw struct {
	// contains filtered or unexported fields
}

func New

func New(s string) (r Raw)

func (Raw) ExpectedType

func (r Raw) ExpectedType() (t Type)

func (Raw) PathString

func (r Raw) PathString() (s string)

func (*Raw) Set

func (r *Raw) Set(s string) (err error)

func (Raw) ToDir

func (r Raw) ToDir() (d Dir)

func (Raw) ToFile

func (r Raw) ToFile() (f File)

func (Raw) WithType

func (r Raw) WithType(t Type) (raw Raw)

type Ref

type Ref struct {
	// contains filtered or unexported fields
}

func (Ref) Join

func (r Ref) Join(parts ...string) Ref

func (Ref) String

func (r Ref) String() string

type SelectedExtensions

type SelectedExtensions struct {
	// contains filtered or unexported fields
}

func (SelectedExtensions) FilterPath

func (s SelectedExtensions) FilterPath(p string) (b bool, err error)

func (SelectedExtensions) FilterPaths

func (s SelectedExtensions) FilterPaths(bools filter.Bools, paths []string) (err error)

type SplitMethods

type SplitMethods interface {
	Split(path string) (dir, file string)
	SplitList(path string) []string
}

type StdMethods

type StdMethods struct{}

func GetStdMethods

func GetStdMethods() *StdMethods

func (StdMethods) Glob

func (StdMethods) Glob(pattern string) ([]string, error)

func (StdMethods) HasPrefix

func (StdMethods) HasPrefix(p, prefix string) bool

func (StdMethods) IsAbs

func (StdMethods) IsAbs(path string) bool

func (StdMethods) Join

func (StdMethods) Join(parts ...string) string

func (StdMethods) Match

func (StdMethods) Match(pattern, name string) (bool, error)

func (StdMethods) Rel

func (StdMethods) Rel(base, target string) (string, error)

func (StdMethods) Split

func (StdMethods) Split(path string) (dir, file string)

func (StdMethods) SplitParts

func (StdMethods) SplitParts(path string) []string

func (StdMethods) UnaryOp

func (StdMethods) UnaryOp(op UnaryOp, path string) (string, error)

type Stringer

type Stringer interface {
	PathString() string
}

type Type

type Type int
const (
	TypeNoCheck Type = iota
	TypeFile
	TypeDirectory
)

func (Type) Is

func (t Type) Is(other Type) (b bool)

func (Type) MustBe

func (t Type) MustBe(other Type) (err error)

func (*Type) Set

func (t *Type) Set(s string) (err error)

func (Type) String

func (t Type) String() (s string)

type UnaryMethods

type UnaryMethods interface {
	DoUnary(op UnaryOp, path string) (string, error)
}

type UnaryOp

type UnaryOp int

ENUM(

Abs
Clean
Dir
EvalSymlinks
Ext
FromSlash
ToSlash
VolumeName

)

const (
	// UnaryOpAbs is a UnaryOp of type Abs.
	UnaryOpAbs UnaryOp = iota
	// UnaryOpClean is a UnaryOp of type Clean.
	UnaryOpClean
	// UnaryOpDir is a UnaryOp of type Dir.
	UnaryOpDir
	// UnaryOpEvalSymlinks is a UnaryOp of type EvalSymlinks.
	UnaryOpEvalSymlinks
	// UnaryOpExt is a UnaryOp of type Ext.
	UnaryOpExt
	// UnaryOpFromSlash is a UnaryOp of type FromSlash.
	UnaryOpFromSlash
	// UnaryOpToSlash is a UnaryOp of type ToSlash.
	UnaryOpToSlash
	// UnaryOpVolumeName is a UnaryOp of type VolumeName.
	UnaryOpVolumeName
)

func ParseUnaryOp

func ParseUnaryOp(name string) (UnaryOp, error)

ParseUnaryOp attempts to convert a string to a UnaryOp.

func (UnaryOp) MarshalText

func (x UnaryOp) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (UnaryOp) String

func (x UnaryOp) String() string

String implements the Stringer interface.

func (*UnaryOp) UnmarshalText

func (x *UnaryOp) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type Visitor

type Visitor func(prefix *string, path string, kind PatternKind) (err error)

type WalkMethods

type WalkMethods interface {
	Walk(root string, fn filepath.WalkFunc) error
	WalkDir(root string, fn fs.WalkDirFunc) error
}

Jump to

Keyboard shortcuts

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