bufgen

package
v0.43.3-0...-9926edd Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package bufgen does configuration-based generation.

It is used by the buf generate command.

Index

Constants

View Source
const ExternalConfigV1Beta1FilePath = "buf.gen.yaml"

ExternalConfigV1Beta1FilePath is the default external configuration file path for v1beta1.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Required
	PluginConfigs []*PluginConfig
	// Optional
	Options *Options
	// Optional
	Managed bool
}

Config is a configuration.

func ReadConfig

func ReadConfig(fileOrData string) (*Config, error)

ReadConfig reads the configuration from the OS.

This will first check if the override ends in .json or .yaml, if so, this reads the file at this path and uses it. Otherwise, this assumes this is configuration data in either JSON or YAML format, and unmarshals it.

Only use in CLI tools.

type ExternalConfigV1Beta1

type ExternalConfigV1Beta1 struct {
	Version string                        `json:"version,omitempty" yaml:"version,omitempty"`
	Managed bool                          `json:"managed,omitempty" yaml:"managed,omitempty"`
	Plugins []ExternalPluginConfigV1Beta1 `json:"plugins,omitempty" yaml:"plugins,omitempty"`
	Options ExternalOptionsConfigV1Beta1  `json:"options,omitempty" yaml:"options,omitempty"`
}

ExternalConfigV1Beta1 is an external configuration.

Only use outside of this package for testing.

type ExternalOptionsConfigV1Beta1

type ExternalOptionsConfigV1Beta1 struct {
	CcEnableArenas    *bool  `json:"cc_enable_arenas,omitempty" yaml:"cc_enable_arenas,omitempty"`
	JavaMultipleFiles *bool  `json:"java_multiple_files,omitempty" yaml:"java_multiple_files,omitempty"`
	OptimizeFor       string `json:"optimize_for,omitempty" yaml:"optimize_for,omitempty"`
}

ExternalOptionsConfigV1Beta1 is an external options configuration.

Only use outside of this package for testing.

type ExternalPluginConfigV1Beta1

type ExternalPluginConfigV1Beta1 struct {
	Name     string      `json:"name,omitempty" yaml:"name,omitempty"`
	Out      string      `json:"out,omitempty" yaml:"out,omitempty"`
	Opt      interface{} `json:"opt,omitempty" yaml:"opt,omitempty"`
	Path     string      `json:"path,omitempty" yaml:"path,omitempty"`
	Strategy string      `json:"strategy,omitempty" yaml:"strategy,omitempty"`
}

ExternalPluginConfigV1Beta1 is an external plugin configuration.

Only use outside of this package for testing.

type GenerateOption

type GenerateOption func(*generateOptions)

GenerateOption is an option for Generate.

func GenerateWithBaseOutDirPath

func GenerateWithBaseOutDirPath(baseOutDirPath string) GenerateOption

GenerateWithBaseOutDirPath returns a new GenerateOption that uses the given base directory as the output directory.

The default is to use the current directory.

type Generator

type Generator interface {
	// Generate calls the generation logic.
	//
	// The config is assumed to be valid. If created by ReadConfig, it will
	// always be valid.
	Generate(
		ctx context.Context,
		container app.EnvStdioContainer,
		config *Config,
		image bufimage.Image,
		options ...GenerateOption,
	) error
}

Generator generates Protobuf stubs based on configurations.

func NewGenerator

func NewGenerator(
	logger *zap.Logger,
	storageosProvider storageos.Provider,
) Generator

NewGenerator returns a new Generator.

type Options

type Options struct {
	CcEnableArenas    *bool
	JavaMultipleFiles *bool
	OptimizeFor       *descriptorpb.FileOptions_OptimizeMode
}

Options is an option configuration.

type PluginConfig

type PluginConfig struct {
	// Required
	Name string
	// Required
	Out string
	// Optional
	Opt string
	// Optional
	Path string
	// Required
	Strategy Strategy
}

PluginConfig is a plugin configuration.

type Strategy

type Strategy int

Strategy is a generation stategy.

const (
	// StrategyDirectory is the strategy that says to generate per directory.
	//
	// This is the default value.
	StrategyDirectory Strategy = 1
	// StrategyAll is the strategy that says to generate with all files at once.
	StrategyAll Strategy = 2
)

func ParseStrategy

func ParseStrategy(s string) (Strategy, error)

ParseStrategy parses the Strategy.

If the empty string is provided, this is interpreted as StrategyDirectory.

func (Strategy) String

func (s Strategy) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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