bufcli

package
v1.61.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 65 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultArchiveStatus is the default archive status.
	//
	// This is currently unarchived.
	DefaultArchiveStatus = unarchivedArchiveStatus
)
View Source
const Version = "1.66.1-dev"

Version is the CLI version of buf.

Variables

View Source
var (
	// ErrNotATTY is returned when an input io.Reader is not a TTY where it is expected.
	ErrNotATTY = errors.New("reader was not a TTY as expected")

	// ErrNoConfigFile is used when the user tries to execute a command without a configuration file.
	ErrNoConfigFile = errors.New(`no buf.yaml file discovered in the specified directory`)
)
View Source
var (
	// AllCacheRelDirPaths are all directory paths for all time
	// concerning the module and plugin caches.
	//
	// These are normalized.
	// These are relative to container.CacheDirPath().
	//
	// This variable is used for clearing the cache.
	AllCacheRelDirPaths = []string{
		v1CacheModuleDataRelDirPath,
		v1CacheModuleLockRelDirPath,
		v1CacheModuleSumRelDirPath,
		v1beta1CacheModuleDataRelDirPath,
		v1beta1CacheModuleLockRelDirPath,
		v2CacheModuleRelDirPath,
		v3CacheCommitsRelDirPath,
		v3CacheModuleLockRelDirPath,
		v3CacheModuleRelDirPath,
		v3CachePluginRelDirPath,
		v3CachePolicyRelDirPath,
		v3CacheWKTRelDirPath,
		v3CacheWasmRuntimeRelDirPath,
	}
)
View Source
var AllLintFormatStrings = append(
	bufanalysis.AllFormatStrings,
	"config-ignore-yaml",
)

AllLintFormatStrings are all format strings for lint.

View Source
var AllRuleFormatStrings = []string{
	"text",
	"json",
}

AllRuleFormatStrings is all rule format strings.

Functions

func ArchiveStatusFlagToModuleArchiveStatusFilter

func ArchiveStatusFlagToModuleArchiveStatusFilter(archiveStatus string) (modulev1.ListLabelsRequest_ArchiveFilter, error)

ArchiveStatusFlagToModuleArchiveStatusFilter parses the given string as a modulev1.ListLabelsRequest_ArchiveFilter.

func ArchiveStatusFlagToPluginArchiveStatusFilter

func ArchiveStatusFlagToPluginArchiveStatusFilter(archiveStatus string) (pluginv1beta1.ListLabelsRequest_ArchiveFilter, error)

ArchiveStatusFlagToPluginArchiveStatusFilter parses the given string as a pluginv1beta1.ListLabelsRequest_ArchiveFilter.

func ArchiveStatusFlagToPolicyArchiveStatusFilter

func ArchiveStatusFlagToPolicyArchiveStatusFilter(archiveStatus string) (policyv1beta1.ListLabelsRequest_ArchiveFilter, error)

ArchiveStatusFlagToPolicyArchiveStatusFilter parses the given string as a pluginv1beta1.ListLabelsRequest_ArchiveFilter.

func BindArchiveStatus

func BindArchiveStatus(flagSet *pflag.FlagSet, addr *string, flagName string)

BindArchiveStatus binds the archive-status flag. Kept in this package so we can keep allArchiveStatusStrings private.

func BindAsFileDescriptorSet

func BindAsFileDescriptorSet(flagSet *pflag.FlagSet, addr *bool, flagName string)

BindAsFileDescriptorSet binds the exclude-imports flag.

func BindCreateVisibility

func BindCreateVisibility(flagSet *pflag.FlagSet, addr *string, flagName string, createFlagName string)

BindCreateVisibility binds the create-visibility flag. Kept in this package so we can keep allVisibilityStrings private.

func BindDisableSymlinks(flagSet *pflag.FlagSet, addr *bool, flagName string)

BindDisableSymlinks binds the disable-symlinks flag.

func BindExcludeImports

func BindExcludeImports(flagSet *pflag.FlagSet, addr *bool, flagName string)

BindExcludeImports binds the exclude-imports flag.

func BindExcludePaths

func BindExcludePaths(
	flagSet *pflag.FlagSet,
	excludePathsAddr *[]string,
	excludePathsFlagName string,
)

BindExcludePaths binds the exclude-path flag.

func BindExcludeSourceInfo

func BindExcludeSourceInfo(flagSet *pflag.FlagSet, addr *bool, flagName string)

BindExcludeSourceInfo binds the exclude-source-info flag.

func BindInputHashtag

func BindInputHashtag(flagSet *pflag.FlagSet, addr *string)

BindInputHashtag binds the input hashtag flag.

This needs to be added to any command that has the input as the first argument. This deals with the situation "buf build -#format=json" which results in a parse error from pflag.

func BindPaths

func BindPaths(
	flagSet *pflag.FlagSet,
	pathsAddr *[]string,
	pathsFlagName string,
)

BindPaths binds the paths flag.

func BindStringPointer

func BindStringPointer(flagSet *pflag.FlagSet, name string, value **string, usage string)

BindStringPointer binds a string pointer flag, which indicates flag presence, i.e. `--flag ""` is not the same as not passing the flag.

This is useful for buf registry organization/module update, where we only modify the fields specified.

Value must not be nil.

func BindVisibility

func BindVisibility(flagSet *pflag.FlagSet, addr *string, flagName string, emptyDefault bool)

BindVisibility binds the visibility flag.

func BufYAMLFileExistsForDirPath

func BufYAMLFileExistsForDirPath(
	ctx context.Context,
	dirPath string,
) (bool, error)

BufYAMLFileExistsForDirPath returns true if the buf.yaml file exists at the dir path.

func GetBufWorkYAMLFileForDirPath

func GetBufWorkYAMLFileForDirPath(
	ctx context.Context,
	dirPath string,
) (bufconfig.BufWorkYAMLFile, error)

GetBufWorkYAMLFileForDirPath gets the buf.work.yaml file for the directory path.

func GetBufYAMLFileForDirPath

func GetBufYAMLFileForDirPath(
	ctx context.Context,
	dirPath string,
) (bufconfig.BufYAMLFile, error)

GetBufYAMLFileForDirPath gets the buf.yaml file for the directory path.

func GetBufYAMLFileForDirPathOrOverride

func GetBufYAMLFileForDirPathOrOverride(
	ctx context.Context,
	dirPath string,
	override string,
) (bufconfig.BufYAMLFile, error)

GetBufYAMLFileForDirPathOrOverride get the buf.yaml file for either the usually-flag-based override, or if the override is not set, the directory path.

func GetInputLong

func GetInputLong(inputArgDescription string) string

GetInputLong gets the long command description for an input-based command.

func GetInputValue

func GetInputValue(
	container app.ArgContainer,
	inputHashtag string,
	defaultValue string,
) (string, error)

GetInputValue gets the first arg.

Also parses the special input hashtag flag that deals with the situation "buf build -#format=json". The existence of 0 or 1 args should be handled by the Args field on Command.

func GetModuleConfigAndPluginConfigsForProtocPlugin

func GetModuleConfigAndPluginConfigsForProtocPlugin(
	ctx context.Context,
	configOverride string,
	module string,
	pluginPathOverrides map[string]string,
) (bufconfig.ModuleConfig, []bufconfig.PluginConfig, []bufconfig.CheckConfig, error)

GetModuleConfigAndPluginConfigsForProtocPlugin gets the bufmodule.ModuleConfig and [bufmodule.PluginConfig]s for the specified module for the protoc plugin implementations.

The caller can provide overrides for plugin paths in the plugin configurations. The protoc plugin implementations do not support remote plugins. Also, for use-cases such as Bazel, access to local binaries might require an explicit path override. So, this allows callers to pass a map of plugin name to local path to override the plugin configuration.

We also return all check configs for the option bufcheck.WithRelatedCheckConfigs to validate the plugin configs when running lint/breaking.

This is the same in both plugins so we just pulled it out to a common spot.

func GetSourceDirLong

func GetSourceDirLong(inputArgDescription string) string

GetSourceDirLong gets the long command description for a directory-based command.

func GetSourceLong

func GetSourceLong(inputArgDescription string) string

GetSourceLong gets the long command description for an input-based command.

func GetSourceOrModuleLong

func GetSourceOrModuleLong(inputArgDescription string) string

GetSourceOrModuleLong gets the long command description for an input-based command.

func NewAppextContainerForPluginEnv

func NewAppextContainerForPluginEnv(
	pluginEnv protoplugin.PluginEnv,
	appName string,
	logLevelString string,
	logFormatString string,
) (appext.Container, error)

NewAppextContainerForPluginEnv creates a new appext.Container for the PluginEnv.

This is used by the protoc plugins.

func NewCommitProvider

func NewCommitProvider(container appext.Container) (bufmodule.CommitProvider, error)

NewCommitProvider returns a new CommitProvider while creating the required cache directories.

func NewConnectClientConfig

func NewConnectClientConfig(container appext.Container) (*connectclient.Config, error)

NewConnectClientConfig creates a new connect.ClientConfig which uses a token reader to look up the token in the container or in netrc based on the address of each individual client. It is then set in the header of all outgoing requests from clients created using this config.

func NewConnectClientConfigWithToken

func NewConnectClientConfigWithToken(container appext.Container, token string) (*connectclient.Config, error)

NewConnectClientConfigWithToken creates a new connect.ClientConfig with a given token. The provided token is set in the header of all outgoing requests from this provider

func NewController

func NewController(
	container appext.Container,
	options ...bufctl.ControllerOption,
) (bufctl.Controller, error)

NewController returns a new Controller.

func NewGraphProvider

func NewGraphProvider(container appext.Container) (bufmodule.GraphProvider, error)

NewGraphProvider returns a new GraphProvider.

func NewInvalidRemoteError

func NewInvalidRemoteError(err error, remote string, moduleFullName string) error

NewInvalidRemoteError informs the user that the given remote is invalid.

func NewLabelNameAlreadyExistsError

func NewLabelNameAlreadyExistsError(name string) error

NewLabelNameAlreadyExistsError informs the user that a label with that name already exists.

func NewLabelNotFoundError

func NewLabelNotFoundError(ref bufparse.Ref) error

NewLabelNotFoundError informs the user that a Ref does not exist as a label.

func NewModuleDataProvider

func NewModuleDataProvider(container appext.Container) (bufmodule.ModuleDataProvider, error)

NewModuleDataProvider returns a new ModuleDataProvider while creating the required cache directories.

func NewModuleKeyProvider

func NewModuleKeyProvider(container appext.Container) (bufmodule.ModuleKeyProvider, error)

NewModuleKeyProvider returns a new ModuleKeyProvider.

func NewModuleNameAlreadyExistsError

func NewModuleNameAlreadyExistsError(name string) error

NewModuleNameAlreadyExistsError informs the user that a module with that name already exists.

func NewModuleNotFoundError

func NewModuleNotFoundError(name string) error

NewModuleNotFoundError informs the user that a module with that name does not exist.

func NewModuleUploader

func NewModuleUploader(container appext.Container) (bufmodule.Uploader, error)

NewModuleUploader returns a new Uploader for ModuleSets.

func NewOrganizationNameAlreadyExistsError

func NewOrganizationNameAlreadyExistsError(name string) error

NewOrganizationNameAlreadyExistsError informs the user that an organization with that name already exists.

func NewOrganizationNotFoundError

func NewOrganizationNotFoundError(name string) error

NewOrganizationNotFoundError informs the user that an organization with that name does not exist.

func NewOrganizationOrUserNotFoundError

func NewOrganizationOrUserNotFoundError(name string) error

NewOrganizationOrUserNotFoundError informs the user that an organization or user with that name does not exist.

func NewPluginDataProvider

func NewPluginDataProvider(container appext.Container) (bufplugin.PluginDataProvider, error)

NewPluginDataProvider returns a new PluginDataProvider while creating the required cache directories.

func NewPluginKeyProvider

func NewPluginKeyProvider(container appext.Container) (bufplugin.PluginKeyProvider, error)

NewPluginKeyProvider returns a new PluginKeyProvider.

func NewPluginNameAlreadyExistsError

func NewPluginNameAlreadyExistsError(name string) error

NewPluginNameAlreadyExistsError informs the user that a plugin with that name already exists.

func NewPluginNotFoundError

func NewPluginNotFoundError(name string) error

NewPluginNotFoundError informs the user that a plugin with that name does not exist.

func NewPluginUploader

func NewPluginUploader(container appext.Container) (bufplugin.Uploader, error)

NewPluginUploader returns a new Uploader for Plugins.

func NewPolicyDataProvider

func NewPolicyDataProvider(container appext.Container) (bufpolicy.PolicyDataProvider, error)

NewPolicyDataProvider returns a new PolicyDataProvider while creating the required cache directories.

func NewPolicyKeyProvider

func NewPolicyKeyProvider(container appext.Container) (bufpolicy.PolicyKeyProvider, error)

NewPolicyKeyProvider returns a new PolicyKeyProvider.

func NewPolicyNameAlreadyExistsError

func NewPolicyNameAlreadyExistsError(name string) error

NewPolicyNameAlreadyExistsError informs the user that a policy with that name already exists.

func NewPolicyNotFoundError

func NewPolicyNotFoundError(name string) error

NewPolicyNotFoundError informs the user that a plugin with that name does not exist.

func NewPolicyUploader

func NewPolicyUploader(container appext.Container) (bufpolicy.Uploader, error)

NewPolicyUploader returns a new Uploader for Policys.

func NewRefNotFoundError

func NewRefNotFoundError(ref bufparse.Ref) error

NewRefNotFoundError informs the user that a Ref does not exist.

func NewTokenNotFoundError

func NewTokenNotFoundError(tokenID string) error

NewTokenNotFoundError informs the user that a token with that identifier does not exist.

func NewTooManyEmptyAnswersError

func NewTooManyEmptyAnswersError(attempts int) error

NewTooManyEmptyAnswersError is used when the user does not answer a prompt in the given number of attempts.

func NewWKTStore

func NewWKTStore(container appext.Container) (bufwktstore.Store, error)

NewWKTStore returns a new bufwktstore.Store while creating the required cache directories.

func NewWasmRuntime

func NewWasmRuntime(ctx context.Context, container appext.Container) (wasm.Runtime, error)

NewWasmRuntime returns a new Wasm runtime while creating the required cache directories.

func PrintFileAnnotationSetLintConfigIgnoreYAMLV1

func PrintFileAnnotationSetLintConfigIgnoreYAMLV1(
	writer io.Writer,
	fileAnnotationSet bufanalysis.FileAnnotationSet,
) error

PrintFileAnnotationSetLintConfigIgnoreYAMLV1 prints the FileAnnotationSet to the Writer for the lint config-ignore-yaml format.

TODO FUTURE: This is messed.

func PrintRules

func PrintRules(writer io.Writer, rules []bufcheck.Rule, format string, includeDeprecated bool) error

PrintRules prints the Rules to the writer given the --format and --include-deprecated flag values.

func PromptUser

func PromptUser(container app.Container, prompt string) (string, error)

PromptUser reads a line from Stdin, prompting the user with the prompt first. The prompt is repeatedly shown until the user provides a non-empty response. ErrNotATTY is returned if the input containers Stdin is not a terminal.

func PromptUserForDelete

func PromptUserForDelete(container app.Container, entityType string, expectedAnswer string) error

PromptUserForDelete is used to receive user confirmation that a specific entity should be deleted. If the user's answer does not match the expected answer, an error is returned. ErrNotATTY is returned if the input containers Stdin is not a terminal.

func PromptUserForPassword

func PromptUserForPassword(container app.Container, prompt string) (string, error)

PromptUserForPassword reads a line from Stdin, prompting the user with the prompt first. The prompt is repeatedly shown until the user provides a non-empty response. ErrNotATTY is returned if the input containers Stdin is not a terminal.

func PutBufYAMLFileForDirPath

func PutBufYAMLFileForDirPath(
	ctx context.Context,
	dirPath string,
	bufYAMLFile bufconfig.BufYAMLFile,
) error

PutBufYAMLFileForDirPath write the buf.yaml file to the directory path.

func ValidateErrorFormatFlagLint

func ValidateErrorFormatFlagLint(errorFormatString string, errorFormatFlagName string) error

ValidateErrorFormatFlagLint validates the error format flag for lint.

func ValidateRequiredFlag

func ValidateRequiredFlag[T comparable](flagName string, value T) error

ValidateRequiredFlag validates that the required flag is set.

func VisibilityFlagToPluginVisibilityAllowUnspecified

func VisibilityFlagToPluginVisibilityAllowUnspecified(visibility string) (pluginv1beta1.PluginVisibility, error)

VisibilityFlagToPluginVisibilityAllowUnspecified parses the given string as a pluginv1.PluginVisibility where an empty string will be parsed as unspecified.

func VisibilityFlagToPolicyVisibilityAllowUnspecified

func VisibilityFlagToPolicyVisibilityAllowUnspecified(visibility string) (policyv1beta1.PolicyVisibility, error)

VisibilityFlagToPolicyVisibilityAllowUnspecified parses the given string as a pluginv1.PolicyVisibility where an empty string will be parsed as unspecified.

func VisibilityFlagToVisibilityAllowUnspecified

func VisibilityFlagToVisibilityAllowUnspecified(visibility string) (modulev1.ModuleVisibility, error)

VisibilityFlagToVisibilityAllowUnspecified parses the given string as a modulev1.ModuleVisibility where an empty string will be parsed as unspecified

func WarnAlphaCommand

func WarnAlphaCommand(_ context.Context, container appext.Container)

WarnAlphaCommand prints a warning for a alpha command unless the alphaSuppressWarningsEnvKey environment variable is set.

func WarnBetaCommand

func WarnBetaCommand(_ context.Context, container appext.Container)

WarnBetaCommand prints a warning for a beta command unless the betaSuppressWarningsEnvKey environment variable is set.

Types

type ModuleOwner

type ModuleOwner interface {
	// String returns "registry/owner".
	fmt.Stringer

	// Registry returns the hostname of the BSR instance that this owner is contained within.
	Registry() string
	// Owner returns the name of the user or organization.
	Owner() string
	// contains filtered or unexported methods
}

ModuleOwner represents a module owner, consisting of a registry and owner.

This concept used to live in bufmodule but it doesn't really make sense there, as it isn't use anywhere else. We only use this in buf registry organization commands at the moment.

func NewModuleOwner

func NewModuleOwner(
	registry string,
	owner string,
) (ModuleOwner, error)

NewModuleOwner returns a new ModuleOwner for the given components.

func ParseModuleOwner

func ParseModuleOwner(moduleOwnerString string) (ModuleOwner, error)

ParseModuleOwner parses a ModuleOwner from a string in the form "registry/owner".

Jump to

Keyboard shortcuts

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