bufconfig

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package bufconfig contains the configuration functionality.

Index

Constants

View Source
const (
	// ExternalConfigFilePath is the default configuration file path.
	ExternalConfigV1FilePath = "buf.yaml"

	// ExternalConfigV1Beta1FilePath is the v1beta1 file path.
	ExternalConfigV1Beta1FilePath = "buf.yaml"

	// V1Version is the v1 version.
	V1Version = "v1"

	// V1Beta1Version is the v1beta1 version.
	V1Beta1Version = "v1beta1"
)

Variables

View Source
var (
	// All versions are all the versions in order.
	AllVersions = []string{
		V1Beta1Version,
		V1Version,
	}
)

Functions

func ExistingConfigFilePath

func ExistingConfigFilePath(ctx context.Context, readBucket storage.ReadBucket) (string, error)

ExistingConfigFilePath checks if a configuration file exists, and if so, returns the path within the ReadBucket of this configuration file.

Returns empty string and no error if no configuration file exists.

func WriteConfig

func WriteConfig(
	ctx context.Context,
	writeBucket storage.WriteBucket,
	options ...WriteConfigOption,
) error

WriteConfig writes an initial configuration file into the bucket.

Types

type Config

type Config struct {
	Version        string
	ModuleIdentity bufmoduleref.ModuleIdentity
	Build          *bufmoduleconfig.Config
	Breaking       *bufbreakingconfig.Config
	Lint           *buflintconfig.Config
}

Config is the user config.

func GetConfigForBucket

func GetConfigForBucket(ctx context.Context, readBucket storage.ReadBucket) (*Config, error)

GetConfigForBucket gets the Config for the YAML data at ConfigFilePath.

If the data is of length 0, returns the default config.

func GetConfigForData

func GetConfigForData(ctx context.Context, data []byte) (*Config, error)

GetConfig gets the Config for the given JSON or YAML data.

If the data is of length 0, returns the default config.

func ReadConfigOS

func ReadConfigOS(
	ctx context.Context,
	readBucket storage.ReadBucket,
	options ...ReadConfigOSOption,
) (*Config, error)

ReadConfigOS reads the configuration from the OS or an override, if any.

ONLY USE IN CLI TOOLS.

type ExternalConfigV1

type ExternalConfigV1 struct {
	Version  string                             `json:"version,omitempty" yaml:"version,omitempty"`
	Name     string                             `json:"name,omitempty" yaml:"name,omitempty"`
	Deps     []string                           `json:"deps,omitempty" yaml:"deps,omitempty"`
	Build    bufmoduleconfig.ExternalConfigV1   `json:"build,omitempty" yaml:"build,omitempty"`
	Breaking bufbreakingconfig.ExternalConfigV1 `json:"breaking,omitempty" yaml:"breaking,omitempty"`
	Lint     buflintconfig.ExternalConfigV1     `json:"lint,omitempty" yaml:"lint,omitempty"`
}

ExternalConfigV1 represents the on-disk representation of the Config at version v1.

type ExternalConfigV1Beta1

type ExternalConfigV1Beta1 struct {
	Version  string                                  `json:"version,omitempty" yaml:"version,omitempty"`
	Name     string                                  `json:"name,omitempty" yaml:"name,omitempty"`
	Deps     []string                                `json:"deps,omitempty" yaml:"deps,omitempty"`
	Build    bufmoduleconfig.ExternalConfigV1Beta1   `json:"build,omitempty" yaml:"build,omitempty"`
	Breaking bufbreakingconfig.ExternalConfigV1Beta1 `json:"breaking,omitempty" yaml:"breaking,omitempty"`
	Lint     buflintconfig.ExternalConfigV1Beta1     `json:"lint,omitempty" yaml:"lint,omitempty"`
}

ExternalConfigV1Beta1 represents the on-disk representation of the Config at version v1beta1.

type ExternalConfigVersion

type ExternalConfigVersion struct {
	Version string `json:"version,omitempty" yaml:"version,omitempty"`
}

ExternalConfigVersion defines the subset of all config file versions that is used to determine the configuration version.

type ReadConfigOSOption

type ReadConfigOSOption func(*readConfigOSOptions)

ReadConfigOSOption is an option for ReadConfig.

func ReadConfigOSWithOverride

func ReadConfigOSWithOverride(override string) ReadConfigOSOption

ReadConfigOSWithOverride sets the override.

If override is set, 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.

If no override is set, this reads ExternalConfigFilePath in the bucket.

type WriteConfigOption

type WriteConfigOption func(*writeConfigOptions)

WriteConfigOption is an option for WriteConfig.

func WriteConfigWithDependencyModuleReferences

func WriteConfigWithDependencyModuleReferences(dependencyModuleReferences ...bufmoduleref.ModuleReference) WriteConfigOption

WriteConfigWithDependencyModuleReferences returns a new WriteConfigOption that sets the dependencies of the module.

The default is to not have any dependencies. If this option is used, WriteConfigWithModuleIdentity must also be used.

Only use in tests.

func WriteConfigWithDocumentationComments

func WriteConfigWithDocumentationComments() WriteConfigOption

WriteConfigWithDocumentationComments returns a new WriteConfigOption that documents the resulting configuration file.

func WriteConfigWithModuleIdentity

func WriteConfigWithModuleIdentity(moduleIdentity bufmoduleref.ModuleIdentity) WriteConfigOption

WriteConfigWithModuleIdentity returns a new WriteConfigOption that sets the name of the module to the given ModuleIdentity.

The default is to not set the name.

Only use in tests.

func WriteConfigWithUncomment

func WriteConfigWithUncomment() WriteConfigOption

WriteConfigWithUncomment returns a new WriteConfigOption that uncomments the resulting configuration file options that are commented out by default.

If this option is used, WriteConfigWithDocumentationComments must also be used.

Jump to

Keyboard shortcuts

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