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 ¶
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 ¶
FormatFile runs formatter on input and returns the formatted result.
func Process ¶
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.
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.