patch

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 8 Imported by: 0

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 applies a documentation patch to the given code using the provided
	// Language implementation. It takes a context, an identifier, a doc string, and
	// a slice of bytes representing the code. It returns a slice of bytes with the
	// patched code or an error if something went wrong.
	Patch(ctx context.Context, identifier, doc string, code []byte) ([]byte, error)
}

Language is an interface that defines the Patch method for applying patches to code documentation. It takes a context, an identifier, a documentation string, and a byte slice of code, and returns a patched byte slice of code along with any errors encountered during the process.

type Option

type Option func(*Patch)

Option is a function that modifies a Patch configuration. It is used as an argument for the New function to customize the behavior of the Patch instance. Common options include WithErrors to provide an error channel and WithLogger to provide a custom logger.

func WithErrors added in v0.0.4

func WithErrors(errs <-chan error) Option

WithErrors configures a Patch to receive errors from the provided error channel. These errors are logged as warnings and don't cause the patching process to fail.

func WithLogger

func WithLogger(h slog.Handler) Option

WithLogger sets the logger for a Patch instance using the provided slog.Handler.

type Patch

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

Patch applies generated documentation to source code files by processing those files and applying the appropriate language-specific patches. It can be configured with a custom error channel and logger, and provides methods for dry run and actual application of patches. The patching process is based on the provided Language interface implementation for each file extension.

func New

func New(files <-chan generate.File, opts ...Option) *Patch

New creates a new Patch instance with the provided generate.File channel and optional configuration options. The returned Patch can be used to apply generated documentation patches to code files.

func (*Patch) Apply

func (p *Patch) Apply(ctx context.Context, repo afero.Fs, getLanguage func(string) (Language, error)) error

Apply applies patches to the generated files provided by the generate.File channel. It reads each file, applies patches using the provided Language service, and writes the patched content back to the file. Errors encountered during patching are logged and do not stop the process. The function returns when all files have been processed or the context is done.

func (*Patch) DryRun

func (p *Patch) DryRun(ctx context.Context, repo afero.Fs, getLanguage func(string) (Language, error)) (map[string][]byte, error)

DryRun performs a dry run of applying patches to the given repository, returning a map of file paths to their resulting patched content without writing any changes. It uses the provided function to get a language-specific patching service for each file based on its extension.

Jump to

Keyboard shortcuts

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