command

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGenerateCommandIsNil is returned when the generate function is nil.
	ErrGenerateCommandIsNil = errors.New("generate command is nil")
	// ErrRequestCompilerVersionIsNil is returned when the request compiler version is nil.
	ErrRequestCompilerVersionIsNil = errors.New("request compiler version is nil")
	// ErrProtoFileNameIsEmpty is returned when the proto file name is empty.
	ErrProtoFileNameIsEmpty = errors.New("proto file name is empty")
	// ErrFileDescriptorIsNil is returned when the file descriptor is nil.
	ErrFileDescriptorIsNil = errors.New("file descriptor is nil")
	// ErrDuplicateProtoFile is returned when the proto file is duplicated.
	ErrDuplicateProtoFile = errors.New("duplicate proto file")
	// ErrFileHasNoKnownDescriptor is returned when the file has no known descriptor.
	ErrFileHasNoKnownDescriptor = errors.New("file has no known descriptor")
	// ErrUnableToParseOptions is returned when the options are unable to be parsed.
	ErrUnableToParseOptions = errors.New("unable to parse options")
	// ErrGeneratedFileHasNoContent is returned when the generated file has no content.
	ErrGeneratedFileHasNoContent = errors.New("generated file has no content")
)

Functions

This section is empty.

Types

type GenerateCommand

type GenerateCommand struct {
	Name              string
	Version           string
	MinimumEdition    descriptorpb.Edition
	MaximumEdition    descriptorpb.Edition
	SupportedFeatures uint64

	Options                      []opts.Option
	ValidateCodeGeneratorRequest func(req *pluginpb.CodeGeneratorRequest) error
	Generate                     func(pl *PluginContext) error
}

GenerateCommand is a command that transforsm a pluginpb.CodeGeneratorRequest into a PluginContext and delegates to [Generate] to generate the code. The generated code is then returned as a pluginpb.CodeGeneratorResponse.

func (*GenerateCommand) Run

func (cmd *GenerateCommand) Run() error

Run executes the command: reads CodeGeneratorRequest from stdin, parses flags, delegates to Generate, and writes CodeGeneratorResponse to stdout.

type GeneratedFile

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

GeneratedFile is a generated file to be returned in the response. It is a simple wrapper around a bytes.Buffer that provides a few convenience methods.

func (*GeneratedFile) Content

func (g *GeneratedFile) Content() []byte

Content returns the generated file content as a byte slice.

func (*GeneratedFile) Fprint

func (g *GeneratedFile) Fprint(v ...any) (int, error)

Fprint prints the provided values in their default format to the generated file.

func (*GeneratedFile) Fprintf

func (g *GeneratedFile) Fprintf(format string, v ...any) (int, error)

Fprintf prints the provided values in using the provided format to the generated file.

func (*GeneratedFile) P

func (g *GeneratedFile) P(v ...any) (int, error)

P prints a line to the generated file.

func (*GeneratedFile) Write

func (g *GeneratedFile) Write(p []byte) (int, error)

Write appends the provided bytes to the generated file.

type PluginContext

type PluginContext struct {
	Request         *pluginpb.CodeGeneratorRequest
	Files           []*descriptorpb.FileDescriptorProto
	FilesByName     map[string]*descriptorpb.FileDescriptorProto
	FilesToGenerate map[string]bool

	ErrorMessage error
	// contains filtered or unexported fields
}

PluginContext is a protoc plugin invocation context independent of Go-specific protogen.

func (*PluginContext) NewGeneratedFile

func (pl *PluginContext) NewGeneratedFile(filename string) *GeneratedFile

NewGeneratedFile creates a new generated file for the plugin context.

Jump to

Keyboard shortcuts

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