path

package module
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: MIT Imports: 11 Imported by: 13

README

path

path codecov Go Report Card Go Reference

Overview

A simple library to handle file path input in Go.

Features

  • Hanlde absolute and relative paths
  • Globbing (must be quoted)
  • List files in directories recursivly
  • Optional regex to filter results
  • Cli via flag, see example

Caveats

When passing in globbed patterns via cli you must quote them, if you dont bash will expand them and could result in undesired results. go run cmd/main.go -path "/my/globbed/path/*"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains added in v0.8.0

func Contains(input []Entry, needle string) bool

func OnlyNames added in v0.6.0

func OnlyNames(input []Entry) []string

OnlyNames returns a slice of absolute paths (strings) from a given Entry slice.

func WatchDir added in v0.12.0

func WatchDir(ctx context.Context, inputPath string, filter WatchFilter, files chan WatchEvent) error

Types

type DateEntitiesFilter added in v0.12.0

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

DateEntitiesFilter filters fs events by matching ensuring ModTime is within the given date range.

func NewDateEntitiesFilter added in v0.12.0

func NewDateEntitiesFilter(from, to time.Time) DateEntitiesFilter

type DateWatchFilter added in v0.12.0

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

DateWatchFilter filters fs events by matching ensuring ModTime is within the given date range.

func NewDateWatchFilter added in v0.12.0

func NewDateWatchFilter(from, to time.Time) DateWatchFilter

type EntriesFilter added in v0.12.0

type EntriesFilter interface {
	// contains filtered or unexported methods
}

EntitiesFilter interface facilitates filtering entry slices.

type Entry added in v0.6.0

type Entry struct {
	FileInfo     fs.FileInfo
	AbsolutePath string
}

Entry is the currency of this package.

func FilterEntities added in v0.12.0

func FilterEntities(files []Entry, filter EntriesFilter) []Entry

FilterEntities removes files from the slice if they are not accepted by the given filter function.

func ListFiles

func ListFiles(inputPath string) ([]Entry, error)

ListFiles recursively lists all files

func ListFilesWithDateFilter added in v0.6.0

func ListFilesWithDateFilter(inputPath string, beginTime, endTime time.Time) ([]Entry, error)

ListFilesWithDateFilter recursively lists all files, filtering based on modtime.

func ListFilesWithFilter

func ListFilesWithFilter(inputPath string, filterRegex *regexp.Regexp) ([]Entry, error)

ListFilesWithFilter recursively lists all files, filtering the names based on the given regex.

func ListFilesWithMapFilter added in v0.6.0

func ListFilesWithMapFilter(inputPath string, skipMap map[string]struct{}) ([]Entry, error)

ListFilesWithMapFilter recursively lists all files skipping those that exist in the skip map.

func ListFilesWithPermissionsFilter added in v0.6.0

func ListFilesWithPermissionsFilter(inputPath string, min, max uint32) ([]Entry, error)

ListFilesWithPermissionsFilter recursively lists all files skipping those that are not in the given range, inclusive.

func ListFilesWithSizeFilter added in v0.6.0

func ListFilesWithSizeFilter(inputPath string, min, max int64) ([]Entry, error)

ListFilesWithSizeFilter recursively lists all files skipping those that are not in the given range, inclusive.

func NewEntry added in v0.12.0

func NewEntry(inputPath string) (Entry, error)

NewEntry takes a filepath and expands ~ as well as other relative paths to absolute and stats them returning Entry.

func OnlyDirs added in v0.6.0

func OnlyDirs(input []Entry) []Entry

OnlyDirs filters an input slice by returning a slice containing only directories.

func OnlyFiles added in v0.6.0

func OnlyFiles(input []Entry) []Entry

OnlyFiles filters an input slice by returning a slice containing only files.

func (*Entry) IsDir added in v0.9.0

func (e *Entry) IsDir() bool

func (*Entry) String added in v0.6.0

func (e *Entry) String() string

type NoopEntriesFilter added in v0.12.0

type NoopEntriesFilter struct{}

NoopEntriesFilter always returns true, useful for testing.

type NoopWatchFilter added in v0.12.0

type NoopWatchFilter struct{}

type Path

type Path struct {
	GivenInput   string // exactly what the user typed
	ComputedPath Entry  // converts relative paths to absolute
	Files        []Entry
}

Path is a type whose sole purpose is to furfil the flag interface

func (*Path) Get

func (p *Path) Get() []Entry

Get fulfils the flag.Getter interface https://pkg.go.dev/flag#Getter

func (*Path) Set

func (p *Path) Set(s string) error

Set fulfils the flag.Value interface https://pkg.go.dev/flag#Value

func (Path) String

func (p Path) String() string

String fulfils the flag.Value interface https://pkg.go.dev/flag#Value

type PermissionsEntitiesFilter added in v0.12.0

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

PermissionsEntitiesFilter filters fs events by ensuring the given file permissions are within the given range.

func NewPermissionsEntitiesFilter added in v0.12.0

func NewPermissionsEntitiesFilter(min, max uint32) PermissionsEntitiesFilter

type PermissionsWatchFilter added in v0.12.0

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

PermissionsWatchFilter filters fs events by ensuring the given file permissions are within the given range.

func NewPermissionsWatchFilter added in v0.12.0

func NewPermissionsWatchFilter(min, max uint32) PermissionsWatchFilter

type RegexEntitiesFilter added in v0.12.0

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

RegexEntitiesFilter filters fs events by matching file names to a given regex.

func NewRegexEntitiesFilter added in v0.12.0

func NewRegexEntitiesFilter(filterRegex *regexp.Regexp) RegexEntitiesFilter

type RegexWatchFilter added in v0.12.0

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

RegexWatchFilter filters fs events by matching file names to a given regex.

func NewRegexWatchFilter added in v0.12.0

func NewRegexWatchFilter(filterRegex *regexp.Regexp) RegexWatchFilter

type SizeEntitiesFilter added in v0.12.0

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

SizeEntitiesFilter filters fs events by ensuring the given file within the given size range (in bytes).

func NewSizeEntitiesFilter added in v0.12.0

func NewSizeEntitiesFilter(min, max int64) SizeEntitiesFilter

type SizeWatchFilter added in v0.12.0

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

SizeWatchFilter filters fs events by ensuring the given file within the given size range (in bytes).

func NewSizeWatchFilter added in v0.12.0

func NewSizeWatchFilter(min, max int64) SizeWatchFilter

type SkipMapEntitiesFilter added in v0.12.0

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

SkipMapEntitiesFilter filters fs events by ensuring the given file is NOT within the given map.

func NewSkipMapEntitiesFilter added in v0.12.0

func NewSkipMapEntitiesFilter(skipMap map[string]struct{}) SkipMapEntitiesFilter

type SkipMapWatchFilter added in v0.12.0

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

SkipMapWatchFilter filters fs events by ensuring the given file is NOT within the given map.

func NewSkipMapWatchFilter added in v0.12.0

func NewSkipMapWatchFilter(skipMap map[string]struct{}) SkipMapWatchFilter

type WatchEvent added in v0.12.1

type WatchEvent struct {
	Entry
	fsnotify.Op
}

type WatchFilter added in v0.12.0

type WatchFilter interface {
	// contains filtered or unexported methods
}

WatchFilter interface facilitates filtering of file events.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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