setapi

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package setapi implements the setapi open2opaque subcommand, which sets the go_api_flag file option in .proto files.

Index

Constants

This section is empty.

Variables

View Source
var ErrLeadingCommentPreventsEdit = errors.New("leading comment prevents edit, check the logs for more details")

ErrLeadingCommentPreventsEdit signals that no modifications were made because a leading comment exempted an API flag from modification. This error is ignored if Task.ErrorOnExempt is false.

Functions

func FormatFile

func FormatFile(ctx context.Context, input []byte, formatter string) ([]byte, error)

FormatFile runs formatter on input and returns the formatted result.

func Process

func Process(ctx context.Context, task Task, formatter string) ([]byte, error)

Process modifies the API level of a proto file or of a particular message in a proto file, see the doc comment of the type Task for more details. Before returning the modified file content, the file is formatted by executing formatter (use "cat" if you don't have a formatter handy). This function doesn't modify the []byte task.Content.

Types

type Cmd

type Cmd struct {
	// contains filtered or unexported fields
}

Cmd implements the setapi subcommand of the open2opaque tool.

func Command

func Command() *Cmd

Command returns an initialized Cmd for registration with the subcommands package.

func (*Cmd) Execute

func (cmd *Cmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...any) subcommands.ExitStatus

Execute implements subcommand.Command.

func (*Cmd) Name

func (*Cmd) Name() string

Name implements subcommand.Command.

func (*Cmd) SetFlags

func (cmd *Cmd) SetFlags(f *flag.FlagSet)

SetFlags implements subcommand.Command.

func (*Cmd) Synopsis

func (*Cmd) Synopsis() string

Synopsis implements subcommand.Command.

func (*Cmd) Usage

func (*Cmd) Usage() string

Usage implements subcommand.Command.

type Task

type Task struct {
	// Path of the proto file.
	Path string
	// The content of the proto file.
	Content []byte
	// If not empty, set the API level only for the message with this
	// package-local or fully-qualified name, e.g. Msg.NestedMsg or
	// pkgname.Msg.NestedMsg.
	// If empty, set the file-level API level.
	Symbol string

	TargetAPI gofeaturespb.GoFeatures_APILevel
	// If true, skip cleanup steps. If false, perform the following steps:
	// - if all messages in a file are on the same API level, set the whole file
	//   to that level.
	// - remove API flags from all messages that don't need it because they are
	//   on the same API level as the file (or of its parent message for nested
	//   messages in edition protos that use the new edition-feature API flag).
	SkipCleanup bool
	// A leading comment before the Go API flag prevents setapi from
	// modifying it. If a modification was prevent by this mechanism and
	// ErrorOnExempt is true, Process returns an error. Otherwise, the original
	// content is returned.
	ErrorOnExempt bool
}

Task defines the modification of the Go API level of a proto file or a particular message.

Jump to

Keyboard shortcuts

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