pathutil

package
v0.0.0-...-2ee2aa9 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pathutil contains helpers to work with paths

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIsDirectory is an error returned when a path
	// points to a directory instead of a file
	ErrIsDirectory = errors.New("path is a directory")
	// ErrIsNotDirectory is an error returned when a path
	// is expected to points to a directory but isn't
	ErrIsNotDirectory = errors.New("path is not a directory")
	// ErrUnknownType is an error returned when an unknown PathValueType
	// is provided to a method
	ErrUnknownType = errors.New("type unknown")
)
View Source
var ErrNoRepo = errors.New("not a git repository (or any of the parent directories)")

ErrNoRepo is an error returned when no repo are found

Functions

func NewDirPathFlagWithDefault

func NewDirPathFlagWithDefault(defaultPath string) pflag.Value

NewDirPathFlagWithDefault return a new Flag Value that should hold a valid path to a directory

func NewFilePathFlagWithDefault

func NewFilePathFlagWithDefault(defaultPath string) pflag.Value

NewFilePathFlagWithDefault return a new Flag Value that should hold a valid path to a file

func NewPathFlagWithDefault

func NewPathFlagWithDefault(defaultPath string) pflag.Value

NewPathFlagWithDefault return a new Flag Value that should hold a valid path to either a file or a directory

func WorkingTree

func WorkingTree(dotGitDirName string) (path string, err error)

WorkingTree returns the absolute path to the working tree

func WorkingTreeFromPath

func WorkingTreeFromPath(p, dotGitDirName string) (path string, err error)

WorkingTreeFromPath returns the absolute path to the root of a repo containing the provided directory

Types

type PathValue

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

PathValue represents a Flag value to be parsed by spf13/pflag

func (*PathValue) Set

func (v *PathValue) Set(value string) (err error)

Set sets the flag's value. When called multiple times: - If the value is a relative path it will be append to the previous value - If the value is an absolute path: it will overwrite the previous value

func (*PathValue) String

func (v *PathValue) String() string

String returns the flag's value

func (*PathValue) Type

func (v *PathValue) Type() string

Type returns the unique type of the Value

type PathValueType

type PathValueType int

PathValueType represents the type of a path

const (
	// PathValueTypeFile represent file
	PathValueTypeFile PathValueType = iota
	// PathValueTypeDir represent a directory
	PathValueTypeDir
	// PathValueTypeAny represent a either a file or a directory
	PathValueTypeAny
)

Jump to

Keyboard shortcuts

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