Documentation ¶
Index ¶
- type GenerateOption
- type Option
- type Repository
- func (g *Repository) Files(ctx context.Context, repo string, opts ...generate.Option) (<-chan generate.File, <-chan error, error)
- func (g *Repository) Generate(ctx context.Context, repo string, opts ...GenerateOption) (*patch.Patch, error)
- func (g *Repository) Patch(ctx context.Context, repo fs.FS, files <-chan generate.File, ...) (*patch.Patch, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GenerateOption ¶
type GenerateOption func(*generation)
GenerateOption is a type that represents an option for generating files. It is used as an argument to the Generate method of Repository to customize file generation. Two functions are provided to create GenerateOptions: GenerateWith and PatchWith. The former takes a variadic parameter of generate.Options, while the latter takes a variadic parameter of patch.Options.
func GenerateWith ¶
func GenerateWith(opts ...generate.Option) GenerateOption
GenerateWith is an option for generating code with given options. It returns a GenerateOption that appends the given options to the generation.genOpts slice. The slice is later used in generating code.
func PatchWith ¶
func PatchWith(opts ...patch.Option) GenerateOption
PatchWith returns a GenerateOption that appends patch options to the generation. These options are applied when generating a patch for a repository.
type Option ¶
type Option func(*Repository)
Option is a type that represents an optional configuration for a Repository. It is a functional option that can modify the behavior of the Repository constructor. Option values can be passed to the constructor as variadic arguments and applied to the Repository using the Option function. The WithLogger Option sets the logger of the Repository.
func WithLogger ¶
WithLogger returns an Option that sets the logger for a Repository. The logger is used to log messages during generation and patching. The logger must implement slog.Handler.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository represents a Jotbot repository. It provides methods for generating and patching files in the repository. Use the New function to create a new Repository instance. The Generate method generates files in the repository using a generate.Service, while the Patch method patches files in the repository using a patch.Patch. The Files method returns a channel of generated files and any errors encountered during generation.
func New ¶
func New(svc generate.Service, opts ...Option) *Repository
New returns a new *Repository that uses the provided generate.Service. Options can be passed to configure the Repository. Use WithLogger to provide a slog.Handler for logging.
func (*Repository) Files ¶
func (g *Repository) Files(ctx context.Context, repo string, opts ...generate.Option) (<-chan generate.File, <-chan error, error)
Files returns a channel of generate.File(https://pkg.go.dev/github.com/modernice/jotbot/generate#File) and a channel of errors, and an error. It generates files for the repository located at the given `repo` path, using the configured generate.Service(https://pkg.go.dev/github.com/modernice/jotbot/generate#Service) and options. If an error occurs during generation, it is returned immediately. The returned channels are closed when there are no more files or errors to be sent.
func (*Repository) Generate ¶
func (g *Repository) Generate(ctx context.Context, repo string, opts ...GenerateOption) (*patch.Patch, error)
Generate generates a patch for a repository at path repo. It accepts a context.Context and a GenerateOption variadic parameter that is used to configure the generation process. It returns the resulting *patch.Patch and an error (if any).
func (*Repository) Patch ¶
func (g *Repository) Patch(ctx context.Context, repo fs.FS, files <-chan generate.File, opts ...patch.Option) (*patch.Patch, error)
Patch applies comments to the source code files in a file system. It takes a context.Context, an fs.FS, a <-chan generate.File and zero or more patch.Option arguments. It returns a *patch.Patch and an error.