fs

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package fs provides file system operations for ccmd

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDir

func CreateDir(path string) error

CreateDir creates a directory with all necessary parents

func DirExists

func DirExists(path string) bool

DirExists checks if a directory exists

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists

func GetClaudeCommandsDir

func GetClaudeCommandsDir() (string, error)

GetClaudeCommandsDir returns the path to .claude/commands/ directory Creates the directory if it doesn't exist Deprecated: This function uses the home directory instead of project directory. Use project-relative paths (.claude) instead.

func GetWorkingDir

func GetWorkingDir() (string, error)

GetWorkingDir returns the current working directory

func JoinPath

func JoinPath(elem ...string) string

JoinPath joins path elements safely across platforms

func ReadJSONFile

func ReadJSONFile(path string, v interface{}) error

ReadJSONFile reads and unmarshals a JSON file

func ReadYAMLFile

func ReadYAMLFile(path string, v interface{}) error

ReadYAMLFile reads and unmarshals a YAML file

func RemoveDir

func RemoveDir(path string) error

RemoveDir removes a directory and all its contents

func RemoveFile

func RemoveFile(path string) error

RemoveFile removes a file

func WriteJSONFile

func WriteJSONFile(path string, v interface{}) error

WriteJSONFile marshals and writes data to a JSON file with indentation

func WriteYAMLFile

func WriteYAMLFile(path string, v interface{}) error

WriteYAMLFile marshals and writes data to a YAML file

Types

type FileSystem

type FileSystem interface {
	ReadFile(name string) ([]byte, error)
	WriteFile(name string, data []byte, perm os.FileMode) error
	Remove(name string) error
	RemoveAll(path string) error
	Rename(oldpath, newpath string) error
	Stat(name string) (fs.FileInfo, error)
	MkdirAll(path string, perm os.FileMode) error
	ReadDir(name string) ([]fs.DirEntry, error)
	Exists(path string) (bool, error)
}

FileSystem is an interface for file system operations

func NewMemoryFileSystem

func NewMemoryFileSystem() FileSystem

NewMemoryFileSystem returns a new in-memory file system implementation

func NewOSFileSystem

func NewOSFileSystem() FileSystem

NewOSFileSystem returns a new OS file system implementation

type MemFS

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

MemFS is an in-memory implementation of FileSystem for testing

func NewMemFS

func NewMemFS() *MemFS

NewMemFS creates a new in-memory file system

func (*MemFS) Clear

func (m *MemFS) Clear()

Clear removes all files from the file system

func (*MemFS) DirExists added in v1.0.0

func (m *MemFS) DirExists(path string) bool

DirExists checks if a directory exists

func (*MemFS) Exists

func (m *MemFS) Exists(path string) (bool, error)

Exists checks if a path exists

func (*MemFS) FileExists added in v1.0.0

func (m *MemFS) FileExists(path string) bool

FileExists checks if a file exists

func (*MemFS) Getenv

func (m *MemFS) Getenv(key string) string

Getenv gets an environment variable for testing

func (*MemFS) List

func (m *MemFS) List(pattern string) []string

List returns all files matching the pattern

func (*MemFS) MkdirAll

func (m *MemFS) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory named path, along with any necessary parents

func (*MemFS) ReadDir

func (m *MemFS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the directory named by dirname and returns a list of directory entries

func (*MemFS) ReadFile

func (m *MemFS) ReadFile(name string) ([]byte, error)

ReadFile reads the named file and returns its contents

func (*MemFS) Remove

func (m *MemFS) Remove(name string) error

Remove removes the named file or directory

func (*MemFS) RemoveAll

func (m *MemFS) RemoveAll(path string) error

RemoveAll removes path and any children it contains

func (*MemFS) Rename

func (m *MemFS) Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath

func (*MemFS) Setenv

func (m *MemFS) Setenv(key, value string) error

Setenv sets an environment variable for testing

func (*MemFS) Stat

func (m *MemFS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the named file

func (*MemFS) String

func (m *MemFS) String() string

String returns a string representation of the file system for debugging

func (*MemFS) WriteFile

func (m *MemFS) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes data to the named file, creating it if necessary

type OS

type OS struct{}

OS implements FileSystem using the real file system

func (OS) Exists

func (OS) Exists(path string) (bool, error)

Exists checks if a path exists

func (OS) MkdirAll

func (OS) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory named path, along with any necessary parents

func (OS) ReadDir

func (OS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the directory named by dirname and returns a list of directory entries

func (OS) ReadFile

func (OS) ReadFile(name string) ([]byte, error)

ReadFile reads the named file and returns its contents

func (OS) Remove

func (OS) Remove(name string) error

Remove removes the named file or directory

func (OS) RemoveAll

func (OS) RemoveAll(path string) error

RemoveAll removes path and any children it contains

func (OS) Rename

func (OS) Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath

func (OS) Stat

func (OS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the named file

func (OS) WriteFile

func (OS) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes data to the named file, creating it if necessary

Jump to

Keyboard shortcuts

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