Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Patch)
Option represents a functional option that can be used when creating a new Patch instance. It allows customization of the new instance by setting various options such as a logger or an override flag. Use WithLogger to set a logger and Override to set the override flag.
func Override ¶
Override sets the Patch's override flag to the provided boolean value. When the override flag is set to true, existing documentation for a function or type will be overwritten when new documentation is added. When it is false, an error will be returned if there is already documentation for a function or type.
func WithLogger ¶
WithLogger is an Option function that sets a logger for the Patch struct. The logger is used to output debug information during the execution of methods on the Patch struct. The logger must implement slog.Handler.
type Patch ¶
type Patch struct {
// contains filtered or unexported fields
}
Patch represents a code patch for adding or updating documentation comments in Go files. It provides methods for commenting functions, type declarations, and variables/constants. The Patch struct is created with the New function, which takes a file system and options. The Identifiers method returns a map of all the identifiers in the patch that have been commented. The Comment method comments the identifier with the given comment string. The Apply method applies all the patches to the files in a given repository directory. The File method returns the source code of a single file from the patch.
func New ¶
New returns a new *Patch that can be used to update documentation comments in Go source files. The repo argument is a filesystem to read the source files from. Options may be provided to modify the behavior of the patcher. WithLogger sets the logger for the patcher. Override allows existing comments to be overwritten.
func (*Patch) Apply ¶
Apply applies the documentation patches to the source files of the patch. It updates the files with new comments or removes existing ones.
func (*Patch) Comment ¶
Comment is a method of the Patch type. It adds or removes documentation comments to an identifier in a Go source file. The identifier can be a function, variable, constant, or type. If the given comment is an empty string, the existing documentation for that identifier will be removed. If the identifier cannot be found in the file, an error will be returned.
func (*Patch) Commit ¶
Commit commits the changes made by the Patch to the repository as a new git.Commit. The commit message will include a list of all files and identifiers that were updated with documentation.
func (*Patch) DryRun ¶
DryRun returns a map of file paths to their corresponding bytes in the current state of the patch. No changes are made to the files on disk.
func (*Patch) File ¶
File "*Patch.File" returns the source code of the specified file in bytes. It takes a string argument representing the path to the file. If the file is not found in the patch, it returns an error.
func (*Patch) Identifiers ¶
Identifiers returns a map where the keys are file paths and the values are slices of identifiers for functions, types, variables or constants that have been commented using the Comment function.