bufprint

package
v1.43.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 21 Imported by: 32

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllFormatsString is the string representation of all Formats.
	AllFormatsString = stringutil.SliceToString([]string{FormatText.String(), FormatJSON.String()})
)

Functions

func PrintEntity added in v1.39.0

func PrintEntity(writer io.Writer, format Format, entity Entity) error

PrintEntity prints an entity.

If format is FormatText, this prints the information in a table. If format is FormatJSON, this prints the information as a JSON object.

func PrintNames added in v1.39.0

func PrintNames(writer io.Writer, format Format, entities ...Entity) error

PrintNames prints entities' names.

If format is FormatJSON, this also prints information about each entity, the same as calling PrintInfo on each entity.

func PrintPage added in v1.39.0

func PrintPage(
	writer io.Writer,
	format Format,
	nextPageToken string,
	nextPageCommand string,
	entities []Entity,
) error

PrintPage prints a page of entities.

func WithTabWriter

func WithTabWriter(
	writer io.Writer,
	header []string,
	f func(TabWriter) error,
) (retErr error)

WithTabWriter calls a function with a TabWriter.

Shared with internal packages.

Types

type CuratedPluginPrinter added in v1.7.0

type CuratedPluginPrinter interface {
	PrintCuratedPlugin(ctx context.Context, format Format, plugin *registryv1alpha1.CuratedPlugin) error
	PrintCuratedPlugins(ctx context.Context, format Format, nextPageToken string, plugins ...*registryv1alpha1.CuratedPlugin) error
}

CuratedPluginPrinter is a printer for curated plugins.

func NewCuratedPluginPrinter added in v1.7.0

func NewCuratedPluginPrinter(writer io.Writer) CuratedPluginPrinter

NewCuratedPluginPrinter returns a new CuratedPluginPrinter.

type Entity added in v1.39.0

type Entity interface {
	// contains filtered or unexported methods
}

Entity is an entity printed structurally by functions in bufprint package. It's used in "buf registry" commands where the CLI prints a page of entities, such as commits, an entity's info or simply an entity's full name.

When printed by PrintEntity in text format, any field with a field tag in the form of `bufprint:"<field name>[,omitempty]"` is printed.

This means that an implementation of Entity must also be a struct.

func NewCommitEntity added in v1.39.0

func NewCommitEntity(commit *modulev1.Commit, moduleFullName bufmodule.ModuleFullName) Entity

NewCommitEntity returns a new commit entity to print.

func NewLabelEntity added in v1.39.0

func NewLabelEntity(label *modulev1.Label, moduleFullName bufmodule.ModuleFullName) Entity

NewLabelEntity returns a new label entity to print.

func NewModuleEntity added in v1.39.0

func NewModuleEntity(module *modulev1.Module, moduleFullName bufmodule.ModuleFullName) Entity

NewModuleEntity returns a new module entity to print.

func NewOrganizationEntity added in v1.39.0

func NewOrganizationEntity(organization *ownerv1.Organization, remote string) Entity

NewOrganizationEntity returns a new organization entity to print.

type Format

type Format int

Format is a format to print.

const (
	// FormatText is the text format.
	FormatText Format = 1
	// FormatJSON is the JSON format.
	FormatJSON Format = 2
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat parses the format.

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

func (Format) String

func (f Format) String() string

String implements fmt.Stringer.

type StatsPrinter added in v1.17.0

type StatsPrinter interface {
	PrintStats(ctx context.Context, format Format, stats *protostat.Stats) error
}

StatsPrinter is a printer of Stats.

func NewStatsPrinter added in v1.17.0

func NewStatsPrinter(writer io.Writer) StatsPrinter

NewStatsPrinter returns a new StatsPrinter.

type TabWriter

type TabWriter interface {
	Write(values ...string) error
}

TabWriter is a tab writer.

type TokenPrinter

type TokenPrinter interface {
	PrintTokens(ctx context.Context, tokens ...*registryv1alpha1.Token) error
}

TokenPrinter is a token printer.

TODO: update to same format as other printers.

func NewTokenPrinter

func NewTokenPrinter(writer io.Writer, format Format) (TokenPrinter, error)

NewTokenPrinter returns a new TokenPrinter.

TODO: update to same format as other printers.

Jump to

Keyboard shortcuts

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