Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Language ¶ added in v0.0.4
type Language interface { // Patch updates the source code in the given language by inserting or altering // documentation strings identified by an identifier. It takes a context, an // identifier for the documentation to patch, the documentation text, and the // original source code as input. It returns the updated source code or an error // if the patching fails. Patch(ctx context.Context, identifier, doc string, code []byte) ([]byte, error) }
Language represents the ability to update source code with documentation. It takes a context for cancellation, an identifier denoting something of interest within the code, a documentation string that should be associated with the identifier, and the original source code as a byte slice. It returns the updated source code as a byte slice along with any error encountered during the patching process. This interface is intended to be implemented by various programming language-specific services that know how to integrate documentation into their respective code formats.
type Option ¶
type Option func(*Patch)
Option configures a *Patch by setting optional parameters.
func WithErrors ¶ added in v0.0.4
WithErrors specifies an error channel to be used by Patch for error reporting. It modifies the provided Patch instance to receive and handle errors during its operations. This option allows the caller to monitor and respond to errors that occur while Patch is processing files.
func WithLogger ¶
WithLogger configures a Patch instance with a specific slog.Logger to handle logging output. It accepts a slog.Handler which is used to create the new logger. This function is intended to be passed as an option when creating a new Patch instance.
type Patch ¶
type Patch struct {
// contains filtered or unexported fields
}
Patch represents a process for modifying files with documentation updates. It listens for file generation events and applies text patches to the content of these files based on language-specific rules provided by a Language service. Patch supports both dry-run operations, which do not alter the filesystem but return a map of the intended changes, and actual application of changes to the filesystem. It can be configured with various options such as error channels and logging handlers to tailor its behavior during the patching process.
func New ¶
New initializes a new Patch with provided file channel and optional configurations. It ensures the presence of a logger, either provided through options or a no-operation logger by default. It returns the initialized Patch.
func (*Patch) Apply ¶
func (p *Patch) Apply(ctx context.Context, repo afero.Fs, getLanguage func(string) (Language, error)) error
Apply processes a series of files intended for patching, applying the changes defined within them to the corresponding files in the provided filesystem repository. It takes a context for cancellation and timeout control, a filesystem interface to access file data, and a function to retrieve language-specific patching services based on file extensions. This method logs informational messages about its progress and warnings if any issues arise during the patching process. If an error occurs that prevents a file from being patched, Apply continues with the next file without terminating the entire operation. It returns an error only if the context is canceled or closed.
func (*Patch) DryRun ¶
func (p *Patch) DryRun(ctx context.Context, repo afero.Fs, getLanguage func(string) (Language, error)) (map[string][]byte, error)
DryRun simulates the patching process by applying modifications to files in memory and returns the resulting content without writing changes to the file system. It accepts a context, a file system abstraction, and a function to retrieve language-specific patching services based on file extensions. On success, it returns a map associating file paths with their modified content. If an error occurs during the simulation, it returns the partial results along with the encountered error.