### Install Buf with Homebrew Source: https://github.com/bufbuild/buf/blob/main/README.md Install the Buf CLI using Homebrew. This is the recommended installation method for macOS and Linux. ```sh brew install bufbuild/buf/buf ``` -------------------------------- ### Install Buf CLI using Homebrew Source: https://github.com/bufbuild/buf/blob/main/README.md This command installs the Buf CLI, along with related binaries like `protoc-gen-buf-breaking` and `protoc-gen-buf-lint`, and shell completion scripts using Homebrew. ```sh brew install bufbuild/buf/buf ``` -------------------------------- ### Example Protobuf Source Path Source: https://github.com/bufbuild/buf/blob/main/private/pkg/protosourcepath/README.md This is an example of a Protobuf source path, represented as an array of integers. It identifies a specific Protobuf definition by traversing fields and indices from the FileDescriptorProto. ```protobuf [4, 0, 2, 0, 1] ``` -------------------------------- ### Buf Configuration Example Source: https://github.com/bufbuild/buf/blob/main/README.md A minimal buf.yaml configuration file defining the workspace version, module paths, and linting/breaking change detection rules. This file is central to Buf's module and workspace concepts. ```yaml version: v2 modules: - path: proto lint: use: - STANDARD breaking: use: - FILE ``` -------------------------------- ### Get Associated Source Paths API Source: https://github.com/bufbuild/buf/blob/main/private/pkg/protosourcepath/README.md This function retrieves all associated source paths for a given protoreflect.SourcePath. It is expected to always return at least the path itself. ```go func GetAssociatedSourcePaths( ssourcePath protoreflect.SourcePath, ) ([]protoreflect.SourcePath, error) ``` -------------------------------- ### Initialize Workspace and Run Checks Source: https://github.com/bufbuild/buf/blob/main/README.md Initialize a new Buf workspace and run essential checks like build, format, lint, and breaking change detection. Ensure your project adheres to standard Protobuf practices. ```sh buf config init buf build buf format -w buf lint buf breaking --against '.git#branch=main' ``` -------------------------------- ### Build Image Files in Multiple Formats Source: https://github.com/bufbuild/buf/blob/main/cmd/buf/internal/command/convert/testdata/convert/README.md This command builds image files in various formats (bin, binpb, json, txtpb) using 'buf build'. It specifies the proto file and the output path for each extension. ```bash for EXT in bin binpb json txtpb do buf build cmd/buf/internal/command/convert/testdata/convert/bin_json/buf.proto \ --output cmd/buf/internal/command/convert/testdata/convert/bin_json/image.$EXT done ``` -------------------------------- ### Convert JSON to Binary Protobuf Descriptor Source: https://github.com/bufbuild/buf/blob/main/cmd/buf/internal/command/convert/testdata/convert/README.md Use this command to convert a JSON input to a binary protobuf descriptor file. The input is piped and specified with '--from -#format=json'. ```bash echo "{\"one\":\"55\"}" | \ buf convert cmd/buf/testdata/success \ --type buf.Foo \ --from -#format=json \ --to cmd/buf/internal/command/convert/testdata/convert/descriptor.plain.binpb ``` -------------------------------- ### Generate Go Protobuf and ConnectRPC with Remote Plugins Source: https://github.com/bufbuild/buf/blob/main/README.md This configuration generates Go Protobuf types and ConnectRPC handlers from proto files using remote plugins hosted on the BSR. It utilizes managed mode for file options and specifies output directories. ```yaml version: v2 clean: true managed: enabled: true override: - file_option: go_package_prefix value: github.com/acme/weather/gen/go plugins: - remote: buf.build/protocolbuffers/go out: gen/go opt: paths=source_relative - remote: buf.build/connectrpc/gosimple out: gen/go opt: - paths=source_relative - simple inputs: - directory: proto ``` -------------------------------- ### Core Buf CLI Commands Source: https://github.com/bufbuild/buf/blob/main/README.md Commonly used Buf CLI commands for managing Protobuf development. These commands cover building, formatting, linting, detecting breaking changes, generating code, and publishing modules. ```sh buf build buf format -w buf lint buf breaking --against '.git#branch=main' buf generate buf push ``` -------------------------------- ### Push a Module to the Buf Schema Registry Source: https://github.com/bufbuild/buf/blob/main/README.md This command pushes a module to the Buf Schema Registry (BSR), establishing it as a source of truth for Protobuf APIs. Consumers can then depend on this module. ```sh buf push ``` -------------------------------- ### Generate Code with buf generate Source: https://github.com/bufbuild/buf/blob/main/README.md Generate code from Protobuf definitions using a checked-in buf.gen.yaml configuration. This automates the code generation process. ```sh buf generate ``` -------------------------------- ### Generate Fake Buf Lock File Source: https://github.com/bufbuild/buf/blob/main/private/buf/bufworkspace/testdata/basic/README.md Use this script to generate a fake buf.lock file for testing purposes. This is automatically executed by 'make generate'. ```bash bash scripts/fakebuflock.bash ``` -------------------------------- ### Convert JSON to Multiple Payload Formats Source: https://github.com/bufbuild/buf/blob/main/cmd/buf/internal/command/convert/testdata/convert/README.md This command regenerates payload files in various formats (bin, binpb, json, txtpb) from a JSON input. It iterates through extensions and uses 'buf convert' for each. ```bash for EXT in bin binpb json txtpb do echo "{\"one\":\"55\"}" | \ buf convert cmd/buf/internal/command/convert/testdata/convert/bin_json \ --type buf.Foo \ --from -#format=json \ --to cmd/buf/internal/command/convert/testdata/convert/bin_json/payload.$EXT done ``` -------------------------------- ### Convert JSON to Multiple Duration Formats Source: https://github.com/bufbuild/buf/blob/main/cmd/buf/internal/command/convert/testdata/convert/README.md This command regenerates duration files in various formats (bin, binpb, json, txtpb) from a JSON input. It iterates through extensions and uses 'buf convert' for each. ```bash for EXT in bin binpb json txtpb do echo "\"3600s\"" | \ buf convert \ --type google.protobuf.Duration \ --from -#format=json \ --to cmd/buf/internal/command/convert/testdata/convert/bin_json/duration.$EXT done ``` -------------------------------- ### Create New Commit IDs with buf-new-commit-id Source: https://github.com/bufbuild/buf/blob/main/cmd/buf/testdata/imports/cache/README.md Execute this command to generate new commit IDs. This is typically used after making changes that require updated commit identifiers. ```bash buf-new-commit-id ``` -------------------------------- ### Re-generate Digests with buf-digest Source: https://github.com/bufbuild/buf/blob/main/cmd/buf/testdata/imports/cache/README.md Use this command to re-generate digests for the specified module paths. Ensure the paths are correct for your project structure. ```bash buf-digest \ cmd/buf/testdata/imports/success/school \ cmd/buf/testdata/imports/success/people \ cmd/buf/testdata/imports/success/students ``` -------------------------------- ### GetAssociatedSourcePaths Source: https://github.com/bufbuild/buf/blob/main/private/pkg/protosourcepath/README.md Retrieves a list of source paths associated with a given Protobuf source path. It is expected that the path itself will always be included in the returned list. ```APIDOC ## GetAssociatedSourcePaths ### Description This function takes a `protoreflect.SourcePath` and returns a list of associated paths. Associated paths include parent paths and child paths relative to the given source path. ### Signature ```go func GetAssociatedSourcePaths( ssourcePath protoreflect.SourcePath, ) ([]protoreflect.SourcePath, error) ``` ### Parameters #### Path Parameters - **sourcePath** (`protoreflect.SourcePath`) - The input source path for which to find associated paths. ### Returns - `[]protoreflect.SourcePath` - A slice of associated source paths. This list will always contain at least the input `sourcePath`. - `error` - An error if the operation fails. ``` -------------------------------- ### Check for Breaking Changes Against a Git Branch Source: https://github.com/bufbuild/buf/blob/main/README.md This command checks for breaking changes in Protobuf schemas against a specified Git branch. The `--against` flag accepts various sources like branches, BSR modules, or local directories. ```sh buf breaking --against '.git#branch=main' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.