util

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureDirectory

func EnsureDirectory(path string) error

EnsureDirectory ensures a directory exists, creating it if necessary

func ExpandTilde

func ExpandTilde(path string) (string, error)

ExpandTilde replaces a leading tilde (~) in a path with the user's home directory. If the path doesn't start with a tilde, it is returned unchanged. Returns an error if the home directory cannot be determined.

func GetBasePath

func GetBasePath(path string) string

GetBasePath returns the base directory of a file path

func GetRelativePath

func GetRelativePath(basePath, path string) (string, error)

GetRelativePath returns a path relative to a base directory

func GlobWithExcludes

func GlobWithExcludes(patterns []string, baseDir string) ([]string, error)

GlobWithExcludes expands a list of glob patterns, including negative patterns (prefixed with '!'), into a deterministically sorted list of file paths.

Patterns like "**/*.md" match all markdown files recursively while "!**/*_test.md" excludes test files.

The function returns paths relative to baseDir, sorted alphabetically.

func GlobWithExcludesNoBaseDir

func GlobWithExcludesNoBaseDir(patterns []string) ([]string, error)

func IsDirectory

func IsDirectory(path string) bool

IsDirectory returns true if the path is a directory

func IsSub

func IsSub(base, path string) (bool, error)

func JoinPath

func JoinPath(base string, paths ...string) string

JoinPath joins path elements into a single path, handling both absolute and relative paths

func NormalizePath

func NormalizePath(path string) string

NormalizePath normalizes a path for the current platform

func WrapError

func WrapError(err error, message string) error

WrapError wraps an error with additional context

Types

type CustomError

type CustomError interface {
	error
	FormattedError() string
}

CustomError defines the interface for custom error types that can provide formatted error messages

type ErrFileNotFound

type ErrFileNotFound struct {
	Path string
}

ErrFileNotFound represents a file not found error

func (*ErrFileNotFound) Error

func (e *ErrFileNotFound) Error() string

func (*ErrFileNotFound) FormattedError

func (e *ErrFileNotFound) FormattedError() string

FormattedError returns a user-friendly error message for file not found errors

type ErrInvalidAgent

type ErrInvalidAgent struct {
	Type string
}

ErrInvalidAgent represents an unknown agent type error

func (*ErrInvalidAgent) Error

func (e *ErrInvalidAgent) Error() string

func (*ErrInvalidAgent) FormattedError

func (e *ErrInvalidAgent) FormattedError() string

FormattedError returns a user-friendly error message for invalid agent errors

type ErrInvalidConfig

type ErrInvalidConfig struct {
	Reason string
}

ErrInvalidConfig represents an invalid configuration error

func (*ErrInvalidConfig) Error

func (e *ErrInvalidConfig) Error() string

func (*ErrInvalidConfig) FormattedError

func (e *ErrInvalidConfig) FormattedError() string

FormattedError returns a user-friendly error message for invalid configuration errors

type ErrInvalidOutputFormat

type ErrInvalidOutputFormat struct {
	Format string
}

ErrInvalidOutputFormat represents an invalid output format error

func (*ErrInvalidOutputFormat) Error

func (e *ErrInvalidOutputFormat) Error() string

func (*ErrInvalidOutputFormat) FormattedError

func (e *ErrInvalidOutputFormat) FormattedError() string

FormattedError returns a user-friendly error message for invalid output format errors

type ErrMalformedFrontmatter

type ErrMalformedFrontmatter struct {
	Path  string
	Cause error
}

ErrMalformedFrontmatter represents a malformed frontmatter error

func (*ErrMalformedFrontmatter) Error

func (e *ErrMalformedFrontmatter) Error() string

func (*ErrMalformedFrontmatter) FormattedError

func (e *ErrMalformedFrontmatter) FormattedError() string

FormattedError returns a user-friendly error message for malformed frontmatter errors

type ErrParseFailure

type ErrParseFailure struct {
	Path  string
	Cause error
}

ErrParseFailure represents a parsing error

func (*ErrParseFailure) Error

func (e *ErrParseFailure) Error() string

func (*ErrParseFailure) FormattedError

func (e *ErrParseFailure) FormattedError() string

FormattedError returns a user-friendly error message for parsing errors

type ErrTemplateExecution

type ErrTemplateExecution struct {
	Template string
	Cause    error
}

ErrTemplateExecution represents a template execution error

func (*ErrTemplateExecution) Error

func (e *ErrTemplateExecution) Error() string

func (*ErrTemplateExecution) FormattedError

func (e *ErrTemplateExecution) FormattedError() string

FormattedError returns a user-friendly error message for template execution errors

type FileSystem

type FileSystem interface {
	// ReadFile reads a file at the given path
	ReadFile(path string) ([]byte, error)

	// WriteFile writes content to a file
	WriteFile(path string, data []byte) error

	// FileExists checks if a file exists
	FileExists(path string) bool

	// IsFile checks if a path exists and is a regular file
	IsFile(path string) bool

	// IsDir checks if a path exists and is a directory
	IsDir(path string) bool

	// ListFiles lists files matching a pattern
	ListFiles(dir string, pattern string) ([]string, error)

	// ResolvePath resolves a relative path to absolute
	ResolvePath(path string) string

	// GlobWithExcludes expands glob patterns with support for exclusions
	GlobWithExcludes(patterns []string, baseDir string) ([]string, error)
}

FileSystem provides file system operations

type RealFileSystem

type RealFileSystem struct{}

RealFileSystem implements FileSystem with the actual OS file system

func (*RealFileSystem) FileExists

func (fs *RealFileSystem) FileExists(path string) bool

FileExists checks if a file exists

func (*RealFileSystem) GlobWithExcludes

func (fs *RealFileSystem) GlobWithExcludes(patterns []string, baseDir string) ([]string, error)

GlobWithExcludes expands glob patterns with support for exclusions

func (*RealFileSystem) IsDir

func (fs *RealFileSystem) IsDir(path string) bool

IsDir checks if a path exists and is a directory

func (*RealFileSystem) IsFile

func (fs *RealFileSystem) IsFile(path string) bool

IsFile checks if a path exists and is a regular file

func (*RealFileSystem) ListFiles

func (fs *RealFileSystem) ListFiles(dir string, pattern string) ([]string, error)

ListFiles lists files matching a pattern

func (*RealFileSystem) ReadFile

func (fs *RealFileSystem) ReadFile(path string) ([]byte, error)

ReadFile reads a file at the given path

func (*RealFileSystem) ResolvePath

func (fs *RealFileSystem) ResolvePath(path string) string

ResolvePath resolves a relative path to absolute

func (*RealFileSystem) WriteFile

func (fs *RealFileSystem) WriteFile(path string, data []byte) error

WriteFile writes content to a file

Jump to

Keyboard shortcuts

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