core

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package core provides the core functionality for file finding and pattern matching.

Index

Constants

View Source
const (
	ColorRed   = "\033[1;31m" // bold red
	ColorGreen = "\033[0;32m" // green
	ColorReset = "\033[0m"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileContent

type FileContent struct {
	Path      string `json:"path"`
	Name      string `json:"name"`
	Content   string `json:"content"`
	Extension string `json:"extension"`
	Size      int64  `json:"size"`
}

type FileFinder added in v0.0.2

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

FileFinder handles file pattern matching and collection with support for glob patterns, symlinks, and parallel processing.

func NewFileFinder added in v0.0.2

func NewFileFinder(includes, excludes []string, followSymlinks bool) *FileFinder

NewFileFinder creates a new FileFinder with the specified include and exclude patterns. The followSymlinks parameter determines whether symbolic links should be followed.

func (*FileFinder) FindMatchingFiles added in v0.1.1

func (ff *FileFinder) FindMatchingFiles(basePaths []string) ([]string, error)

FindMatchingFiles returns all files that match the include patterns and don't match any exclude patterns. It processes directories in parallel using a worker pool for improved performance. Returns a slice of matched file paths and any error encountered during processing.

func (*FileFinder) GetRealPath added in v0.1.1

func (ff *FileFinder) GetRealPath(path string) (string, error)

GetRealPath returns the real filesystem path for a file, resolving any symbolic links.

func (ff *FileFinder) IsSymlink(path string) (bool, error)

IsSymlink checks if the given path has been seen as a symbolic link during processing.

type FileGroup added in v0.1.1

type FileGroup struct {
	OutputPath string
	Files      []string
}

FileGroup represents a collection of files destined for the same output

type FileManager added in v0.1.1

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

FileManager handles file organization, path management, and size calculations

func NewFileManager added in v0.1.1

func NewFileManager(maxFileSize, maxOutputSize int64, outputType OutputType) *FileManager

NewFileManager creates a new FileManager with the specified size limits and output type

func (*FileManager) DeriveOutputPaths added in v0.1.1

func (fm *FileManager) DeriveOutputPaths(inputPaths []string, customOutputPath string) ([]string, error)

DeriveOutputPaths generates output paths for the given input paths

func (*FileManager) GroupFilesByOutput added in v0.1.1

func (fm *FileManager) GroupFilesByOutput(files []string, outputPaths []string) ([]FileGroup, error)

GroupFilesByOutput organizes files into groups based on their output destinations

func (*FileManager) ParseSize added in v0.1.1

func (fm *FileManager) ParseSize(size string) (int64, error)

ParseSize converts a size string (e.g., "10MB") to bytes

func (*FileManager) ValidateFiles added in v0.1.1

func (fm *FileManager) ValidateFiles(files []string) ([]string, error)

ValidateFiles checks files against size limits and returns valid ones

type FileProcessor added in v0.0.2

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

FileProcessor handles the concurrent processing of multiple files, including content cleaning when enabled. It manages a pool of cleaners for different languages and ensures proper resource cleanup.

func NewFileProcessor added in v0.0.2

func NewFileProcessor(options *MixOptions) *FileProcessor

NewFileProcessor creates a new FileProcessor instance with the specified options. It initializes the cleaner map if cleaning is enabled but defers actual cleaner creation until needed.

func (*FileProcessor) ProcessFiles added in v0.0.2

func (p *FileProcessor) ProcessFiles(paths []string) ([]FileContent, error)

ProcessFiles processes multiple files concurrently using a worker pool pattern. It respects file size limits and handles errors gracefully, continuing to process files even if some fail.

Parameters:

  • paths: Slice of file paths to process

Returns:

  • []FileContent: Slice of successfully processed file contents
  • error: First error encountered during processing, if any

type FileResult

type FileResult struct {
	Content FileContent // Processed file content and metadata
	Error   error       // Error that occurred during processing, if any
}

FileResult represents the outcome of processing a single file. It can contain either the processed content or an error, but not both.

type MixError

type MixError struct {
	File    string
	Message string
}

func (*MixError) Error

func (e *MixError) Error() string

type MixOptions

type MixOptions struct {
	InputPath         string
	OutputPath        string
	Pattern           string
	Exclude           string
	MaxFileSize       int64
	MaxOutputSize     int64
	MaxOutputFileSize int64
	OutputType        OutputType
	CleanerOptions    *cleaner.CleanerOptions
	IgnoreSymlinks    bool
}

func (*MixOptions) Validate added in v0.0.4

func (m *MixOptions) Validate() error

type OutputGenerator added in v0.0.2

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

OutputGenerator handles the creation of output files in various formats

func NewOutputGenerator added in v0.0.2

func NewOutputGenerator(options *MixOptions) (*OutputGenerator, error)

NewOutputGenerator creates a new OutputGenerator instance

func (*OutputGenerator) Generate added in v0.0.2

func (g *OutputGenerator) Generate(contents []FileContent) error

Modify the Generate method in internal/core/output.go to use the new functions:

type OutputType

type OutputType string
const (
	OutputTypeXML  OutputType = "XML"
	OutputTypeJSON OutputType = "JSON"
	OutputTypeYAML OutputType = "YAML"
)

type PatternError added in v0.1.1

type PatternError struct {
	Pattern string
	Reason  string
}

func (*PatternError) Error added in v0.1.1

func (e *PatternError) Error() string

type PatternValidator added in v0.1.1

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

func NewPatternValidator added in v0.1.1

func NewPatternValidator() *PatternValidator

func (*PatternValidator) ExpandPattern added in v0.1.1

func (v *PatternValidator) ExpandPattern(pattern string) ([]string, error)

func (*PatternValidator) ValidatePattern added in v0.1.1

func (v *PatternValidator) ValidatePattern(pattern string) error

type Result added in v0.1.1

type Result struct {
	Path string // The path of the matched file
	Err  error  // Any error encountered during processing
}

Result represents the outcome of a file finding operation. It can contain either a matched file path or an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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