bufcli

package
v0.0.0-...-26f4575 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Version is the CLI version of buf.
	Version = "1.15.0-dev"

	// BetaEnableTamperProofingEnvKey is an env var to enable tamper proofing
	BetaEnableTamperProofingEnvKey = "BUF_BETA_ENABLE_TAMPER_PROOFING"
)
View Source
const (
	// ExitCodeFileAnnotation is the exit code used when we print file annotations.
	//
	// We use a different exit code to be able to distinguish user-parsable errors from
	// system errors.
	ExitCodeFileAnnotation = 100
)

Variables

View Source
var (

	// AllCacheModuleRelDirPaths are all directory paths for all time concerning the module cache.
	//
	// These are normalized.
	// These are relative to container.CacheDirPath().
	//
	// This variable is used for clearing the cache.
	AllCacheModuleRelDirPaths = []string{
		v1beta1CacheModuleDataRelDirPath,
		v1beta1CacheModuleLockRelDirPath,
		v1CacheModuleDataRelDirPath,
		v1CacheModuleLockRelDirPath,
		v1CacheModuleSumRelDirPath,
	}

	// 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")
)
View Source
var (
	// ErrNoModuleName is used when the user does not specify a module name in their configuration file.
	ErrNoModuleName = errors.New(`please specify a module name in your configuration file with the "name" key`)

	// ErrNoConfigFile is used when the user tries to execute a command without a configuration file.
	ErrNoConfigFile = errors.New(`please define a configuration file in the current directory; you can create one by running "buf mod init"`)

	// ErrFileAnnotation is used when we print file annotations and want to return an error.
	//
	// The app package works on the concept that an error results in a non-zero exit
	// code, and we already print the messages with PrintFileAnnotations, so we do
	// not want to print any additional error message.
	//
	// We also exit with 100 to be able to distinguish user-parsable errors from
	// system errors.
	ErrFileAnnotation = app.NewError(ExitCodeFileAnnotation, "")
)

Functions

func BindAsFileDescriptorSet

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

BindAsFileDescriptorSet binds the exclude-imports flag.

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 BindVisibility

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

BindVisibility binds the visibility flag.

func BucketAndConfigForSource

func BucketAndConfigForSource(
	ctx context.Context,
	logger *zap.Logger,
	container app.EnvStdinContainer,
	storageosProvider storageos.Provider,
	runner command.Runner,
	source string,
) (storage.ReadBucketCloser, *bufconfig.Config, error)

BucketAndConfigForSource returns a bucket and config. The bucket contains just the files that constitute a module. It also checks if config exists and defines a module identity, returning ErrNoConfigFile and ErrNoModuleName respectfully.

Workspaces are disabled when fetching the source.

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 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 IsBetaTamperProofingEnabled

func IsBetaTamperProofingEnabled(container app.EnvContainer) (bool, error)

IsBetaTamperProofingEnabled returns if BUF_BETA_ENABLE_TAMPER_PROOFING is set to true.

func NewConfig

func NewConfig(container appflag.Container) (*bufapp.Config, error)

NewConfig creates a new Config.

func NewConnectClientConfig

func NewConnectClientConfig(container appflag.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 appflag.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 NewErrorInterceptor

func NewErrorInterceptor() appflag.Interceptor

NewErrorInterceptor returns a CLI interceptor that wraps Buf CLI errors.

func NewImageForSource

func NewImageForSource(
	ctx context.Context,
	container appflag.Container,
	source string,
	errorFormat string,
	disableSymlinks bool,
	configOverride string,
	externalDirOrFilePaths []string,
	externalExcludeDirOrFilePaths []string,
	externalDirOrFilePathsAllowNotExist bool,
	excludeSourceCodeInfo bool,
) (bufimage.Image, error)

NewImageForSource resolves a single bufimage.Image from the user-provided source with the build options.

func NewInternalError

func NewInternalError(err error) error

NewInternalError represents an internal error encountered by the buf CLI. These errors should not happen and therefore warrant a bug report.

func NewModuleReaderAndCreateCacheDirs

func NewModuleReaderAndCreateCacheDirs(
	container appflag.Container,
	clientConfig *connectclient.Config,
) (bufmodule.ModuleReader, error)

NewModuleReaderAndCreateCacheDirs returns a new ModuleReader while creating the required cache directories.

func NewModuleReaderAndCreateCacheDirsWithExternalPaths

func NewModuleReaderAndCreateCacheDirsWithExternalPaths(
	container appflag.Container,
	clientConfig *connectclient.Config,
) (bufmodule.ModuleReader, error)

NewModuleReaderAndCreateCacheDirsWithExternalPaths returns a new ModuleReader while creating the required cache directories, and configures the cache to preserve external paths.

WARNING - this should only be used by systems like the LSP - leaking external paths from the module cache is otherwise dangerous and requires manager approval.

func NewModuleRefError

func NewModuleRefError(moduleRef string) error

NewModuleRefError is used when the client fails to parse a module ref.

func NewModuleReferenceNotFoundError

func NewModuleReferenceNotFoundError(reference bufmoduleref.ModuleReference) error

NewModuleReferenceNotFoundError informs the user that a module reference does not exist.

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 NewPluginNotFoundError

func NewPluginNotFoundError(owner string, name string) error

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

func NewRepositoryNameAlreadyExistsError

func NewRepositoryNameAlreadyExistsError(name string) error

NewRepositoryNameAlreadyExistsError informs the user that a repository with that name already exists.

func NewRepositoryNotFoundError

func NewRepositoryNotFoundError(name string) error

NewRepositoryNotFoundError informs the user that a repository with that name does not exist.

func NewStorageosProvider

func NewStorageosProvider(disableSymlinks bool) storageos.Provider

NewStorageosProvider returns a new storageos.Provider based on the value of the disable-symlinks flag.

func NewTagOrDraftNameAlreadyExistsError

func NewTagOrDraftNameAlreadyExistsError(name string) error

NewTagOrDraftNameAlreadyExistsError informs the user that a tag or draft with that name already exists.

func NewTemplateNotFoundError

func NewTemplateNotFoundError(owner string, name string) error

NewTemplateNotFoundError informs the user that a template with that owner and name 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 NewUnimplementedRemoteError

func NewUnimplementedRemoteError(err error, remote string, moduleIdentity string) error

func NewWireFileLister

func NewWireFileLister(
	container appflag.Container,
	storageosProvider storageos.Provider,
	runner command.Runner,
	clientConfig *connectclient.Config,
) (bufwire.FileLister, error)

NewWireFileLister returns a new FileLister.

func NewWireImageConfigReader

func NewWireImageConfigReader(
	container appflag.Container,
	storageosProvider storageos.Provider,
	runner command.Runner,
	clientConfig *connectclient.Config,
) (bufwire.ImageConfigReader, error)

NewWireImageConfigReader returns a new ImageConfigReader.

func NewWireImageReader

func NewWireImageReader(
	logger *zap.Logger,
	storageosProvider storageos.Provider,
	runner command.Runner,
) bufwire.ImageReader

NewWireImageReader returns a new ImageReader.

func NewWireImageWriter

func NewWireImageWriter(
	logger *zap.Logger,
) bufwire.ImageWriter

NewWireImageWriter returns a new ImageWriter.

func NewWireModuleConfigReader

func NewWireModuleConfigReader(
	container appflag.Container,
	storageosProvider storageos.Provider,
	runner command.Runner,
	clientConfig *connectclient.Config,
) (bufwire.ModuleConfigReader, error)

NewWireModuleConfigReader returns a new ModuleConfigReader.

func NewWireModuleConfigReaderForModuleReader

func NewWireModuleConfigReaderForModuleReader(
	container appflag.Container,
	storageosProvider storageos.Provider,
	runner command.Runner,
	clientConfig *connectclient.Config,
	moduleReader bufmodule.ModuleReader,
) (bufwire.ModuleConfigReader, error)

NewWireModuleConfigReaderForModuleReader returns a new ModuleConfigReader using the given ModuleReader.

func NewWireProtoEncodingReader

func NewWireProtoEncodingReader(
	logger *zap.Logger,
) bufwire.ProtoEncodingReader

NewWireProtoEncodingReader returns a new ProtoEncodingReader.

func NewWireProtoEncodingWriter

func NewWireProtoEncodingWriter(
	logger *zap.Logger,
) bufwire.ProtoEncodingWriter

NewWireProtoEncodingWriter returns a new ProtoEncodingWriter.

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 receieve 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 ValidateErrorFormatFlag

func ValidateErrorFormatFlag(errorFormatString string, errorFormatFlagName string) error

ValidateErrorFormatFlag validates the error format flag for all commands but lint.

func ValidateErrorFormatFlagLint

func ValidateErrorFormatFlagLint(errorFormatString string, errorFormatFlagName string) error

ValidateErrorFormatFlagLint validates the error format flag for lint.

func VisibilityFlagToVisibility

func VisibilityFlagToVisibility(visibility string) (registryv1alpha1.Visibility, error)

VisibilityFlagToVisibility parses the given string as a registryv1alpha1.Visibility.

func VisibilityFlagToVisibilityAllowUnspecified

func VisibilityFlagToVisibilityAllowUnspecified(visibility string) (registryv1alpha1.Visibility, error)

VisibilityFlagToVisibilityAllowUnspecified parses the given string as a registryv1alpha1.Visibility, where an empty string will be parsed as unspecified

func WarnAlphaCommand

func WarnAlphaCommand(ctx context.Context, container appflag.Container)

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

func WarnBetaCommand

func WarnBetaCommand(ctx context.Context, container appflag.Container)

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

func WellKnownTypeImage

func WellKnownTypeImage(ctx context.Context, logger *zap.Logger, wellKnownType string) (bufimage.Image, error)

WellKnownTypeImage returns the image for the well known type (google.protobuf.Duration for example).

Types

type GlobalFlags

type GlobalFlags struct{}

GlobalFlags contains global flags for buf commands.

func NewGlobalFlags

func NewGlobalFlags() *GlobalFlags

NewGlobalFlags creates a new GlobalFlags with default values..

func (*GlobalFlags) BindRoot

func (*GlobalFlags) BindRoot(*pflag.FlagSet)

BindRoot binds the global flags to the root command flag set.

Jump to

Keyboard shortcuts

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