pathname

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: MIT Imports: 9 Imported by: 0

README

go-pathname

Managing paths conveniently. Inspired by ruby's Pathname.

TLDR

path := pathname.New(p)

if path.Exist() {
	// do something
}

path.Append("abc.txt").AbsolutePath()
path.Children()

// ...
Methods
New(pathString string) Pathname
Raw(pathString string) Pathname
(Pathname) String() string
(Pathname) Append(path string) Pathname
(Pathname) Parent() Pathname
(Pathname) Basename() string
(Pathname) Extension() string
(Pathname) IsAbsolute() bool
(Pathname) AbsolutePath() Pathname
(Pathname) Children() ([]Pathname, error)
(Pathname) Walk(block func(path Pathname, entry fs.DirEntry, err error) error) error
(Pathname) ChildrenNames() ([]string, error)
(Pathname) Mkpath() error
(Pathname) Rmtree() error
(Pathname) Glob(pattern string) []Pathname
(Pathname) AppendRandom() Pathname
(Pathname) Exist() bool
(Pathname) IsDirectory() bool
(Pathname) IsFile() bool
(Pathname) IsRegularFile() bool
(Pathname) IsSymlink() bool
(Pathname) Write(text string) error
(Pathname) Read() (string, error)
(Pathname) MoveTo(path Pathname) error
(Pathname) CopyTo(toPath Pathname) error
(Pathname) CopyFileTo(toPath Pathname) error
(Pathname) SymlinkTo(toPath Pathname) error
(Pathname) Perm() uint32
(Pathname) Chmod(perm uint32) error
(Pathname) Chown(uid int) error
Current() Pathname
TempDir() Pathname
HomeDir() Pathname
(Pathname) Chdir() error
(Pathname) ChdirWithin(block func(path Pathname)) error
ErrIgnore[T any](a T, err error) T
ErrDie[T any](a T, err error) T

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrDie

func ErrDie[T any](a T, err error) T

func ErrIgnore

func ErrIgnore[T any](a T, err error) T

Types

type Pathname

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

Pathname is convenient tool to manipulate filepath inspired by Ruby's Pathname

func Current

func Current() Pathname

func HomeDir

func HomeDir() Pathname

func New

func New(pathString string) Pathname

func Raw

func Raw(pathString string) Pathname

Raw create demo Pathname without any modification

func TempDir

func TempDir() Pathname

func (Pathname) AbsolutePath

func (o Pathname) AbsolutePath() Pathname

AbsolutePath returns an absolute representation of path. If the path is not absolute it will be joined with the current

func (Pathname) Append

func (o Pathname) Append(path string) Pathname

func (Pathname) AppendRandom

func (o Pathname) AppendRandom() Pathname

func (Pathname) Basename

func (o Pathname) Basename() string

func (Pathname) Chdir

func (o Pathname) Chdir() error

func (Pathname) ChdirWithin

func (o Pathname) ChdirWithin(block func(path Pathname)) error

func (Pathname) Children

func (o Pathname) Children() ([]Pathname, error)

func (Pathname) ChildrenNames

func (o Pathname) ChildrenNames() []string

func (Pathname) Chmod

func (o Pathname) Chmod(perm uint32) error

func (Pathname) Chown

func (o Pathname) Chown(uid int) error

func (Pathname) Cleaned added in v1.0.3

func (o Pathname) Cleaned() Pathname

func (Pathname) CopyDirTo

func (o Pathname) CopyDirTo(toPath Pathname) error

CopyDirTo Just demo wrapper of the unix cp command with '-r' the toPath must not exist (while the toPath's parent must exist)

func (Pathname) CopyFileTo

func (o Pathname) CopyFileTo(toPath Pathname) error

func (Pathname) CopyTo

func (o Pathname) CopyTo(toPath Pathname) error

func (Pathname) Exist

func (o Pathname) Exist() bool

func (Pathname) Extension

func (o Pathname) Extension() string

func (Pathname) Glob

func (o Pathname) Glob(pattern string) []Pathname

Glob is the shell style glob Doesn't support '**' as any nested path

func (Pathname) IsAbsolute

func (o Pathname) IsAbsolute() bool

func (Pathname) IsDirectory

func (o Pathname) IsDirectory() bool

func (Pathname) IsFile

func (o Pathname) IsFile() bool

func (Pathname) IsRegularFile

func (o Pathname) IsRegularFile() bool
func (o Pathname) IsSymlink() bool

func (Pathname) Mkpath

func (o Pathname) Mkpath() error

func (Pathname) Mkpath2

func (o Pathname) Mkpath2(perm uint32) error

func (Pathname) MoveTo

func (o Pathname) MoveTo(path Pathname) error

func (Pathname) Parent

func (o Pathname) Parent() Pathname

func (Pathname) Perm

func (o Pathname) Perm() uint32

func (Pathname) Read

func (o Pathname) Read() (string, error)

func (Pathname) Rmtree

func (o Pathname) Rmtree() error

func (Pathname) String

func (o Pathname) String() string

return the string representation

func (Pathname) SymlinkTo

func (o Pathname) SymlinkTo(toPath Pathname) error

func (Pathname) Walk

func (o Pathname) Walk(block func(path Pathname, entry fs.DirEntry, err error) error) error

Walk is just a wrapper of filepath.WalkDir

func (Pathname) Write

func (o Pathname) Write(text string) error

Directories

Path Synopsis
scripts

Jump to

Keyboard shortcuts

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