Skip to content

proto copier#102

Merged
connerohnesorge merged 2 commits into
mainfrom
copier
Oct 13, 2025
Merged

proto copier#102
connerohnesorge merged 2 commits into
mainfrom
copier

Conversation

@connerohnesorge
Copy link
Copy Markdown
Owner

@connerohnesorge connerohnesorge commented Aug 25, 2025

This pull request introduces a comprehensive example for the "Proto Copier" feature in Bufrnix, demonstrating how to declaratively copy Protocol Buffer files to multiple destinations using various configurations. It includes a detailed README, a Nix flake with multiple example scenarios, and a set of realistic proto files organized by use case (API, shared types, external integrations, internal services, and tests). The example is designed to showcase advanced proto distribution patterns, filtering, file transformations, and integration with other language modules.

Key changes:

Documentation & Example Structure

  • Added a detailed README.md explaining the purpose, project structure, available copier configurations, usage instructions, configuration options, output examples, use cases, advanced features, testing steps, integration with other languages, troubleshooting, and links to further reading.

Nix Flake Configuration

  • Introduced flake.nix defining multiple copier scenarios: default copying, advanced multi-destination copying, flattened output with file transformations, selective copying, and combined proto copying with Go code generation. Each scenario demonstrates different filtering and output strategies.

Proto File Examples

Demonstration Outputs

  • Example output files (e.g., output/backend/proto/proto/api/v1/user_service.proto) illustrate the result of running the copier with different configurations.

These changes provide a robust, real-world demonstration of Bufrnix's proto copier capabilities, serving as both documentation and a testbed for users.


References:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive example demonstrating the "Proto Copier" feature in Bufrnix, which enables declarative copying of Protocol Buffer files to multiple destinations using various configurations and filtering options.

  • Adds proto language support with file copying capabilities to the Bufrnix system
  • Implements a new proto copier module with extensive configuration options for file distribution
  • Provides a detailed example project showcasing different proto copying scenarios and use cases

Reviewed Changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/lib/mkBufrnix.nix Adds proto language package entry to supported languages
src/lib/bufrnix-options.nix Defines comprehensive configuration options for proto language and copier sub-module
src/languages/proto/default.nix Main proto language module that orchestrates copying operations
src/languages/proto/copier.nix Core copier implementation with file filtering, transformation, and multi-destination support
examples/proto-copier/ Complete example project with README, flake configuration, and sample proto files
output/ Example output files demonstrating the copier's functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +56 to +58
if [[ "$proto_file" == ${pattern} ]]; then
should_exclude=true
fi
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shell pattern matching is incorrect. The variable should be quoted and use proper glob matching syntax. This should be [[ \"$proto_file\" == *${pattern}* ]] or use a case statement for proper pattern matching.

Suggested change
if [[ "$proto_file" == ${pattern} ]]; then
should_exclude=true
fi
case "$proto_file" in
${pattern}) should_exclude=true ;;
esac

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +66
[[ -n "$proto_file" ]] || continue

Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check for non-empty proto_file is redundant since the same check is performed on line 51. Consider removing this duplicate check to reduce code complexity.

Suggested change
[[ -n "$proto_file" ]] || continue

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +100
target_file="${outputPath}/$rel_path"

${optionalString (filePrefix != "") ''
# Add file prefix
target_file="${outputPath}/$(dirname "$rel_path")/${filePrefix}$(basename "$rel_path")"
''}

${optionalString (fileSuffix != "") ''
# Add file suffix (before extension)
base_name=$(basename "$rel_path" .proto)
target_file="${outputPath}/$(dirname "$rel_path")/$base_name${fileSuffix}.proto"
''}

mkdir -p "$target_dir"
'' else ''
# Flatten files (copy all to output root)
file_name=$(basename "$proto_file")
target_file="${outputPath}/$file_name"

${optionalString (filePrefix != "") ''
# Add file prefix
target_file="${outputPath}/${filePrefix}$file_name"
''}

${optionalString (fileSuffix != "") ''
# Add file suffix (before extension)
base_name=$(basename "$file_name" .proto)
target_file="${outputPath}/$base_name${fileSuffix}.proto"
''}
''}
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file prefix logic overrides the target_file variable set on line 71, making that assignment redundant. Consider restructuring to calculate the final target_file path only once to improve clarity.

Suggested change
target_file="${outputPath}/$rel_path"
${optionalString (filePrefix != "") ''
# Add file prefix
target_file="${outputPath}/$(dirname "$rel_path")/${filePrefix}$(basename "$rel_path")"
''}
${optionalString (fileSuffix != "") ''
# Add file suffix (before extension)
base_name=$(basename "$rel_path" .proto)
target_file="${outputPath}/$(dirname "$rel_path")/$base_name${fileSuffix}.proto"
''}
mkdir -p "$target_dir"
'' else ''
# Flatten files (copy all to output root)
file_name=$(basename "$proto_file")
target_file="${outputPath}/$file_name"
${optionalString (filePrefix != "") ''
# Add file prefix
target_file="${outputPath}/${filePrefix}$file_name"
''}
${optionalString (fileSuffix != "") ''
# Add file suffix (before extension)
base_name=$(basename "$file_name" .proto)
target_file="${outputPath}/$base_name${fileSuffix}.proto"
''}
''}
# Build the target filename with optional prefix and suffix
base_name=$(basename "$rel_path" .proto)
file_name="${base_name}.proto"
if [ -n "${filePrefix}" ]; then
file_name="${filePrefix}${file_name}"
fi
if [ -n "${fileSuffix}" ]; then
file_name="${base_name}${fileSuffix}.proto"
if [ -n "${filePrefix}" ]; then
file_name="${filePrefix}${base_name}${fileSuffix}.proto"
fi
fi
target_file="${target_dir}/${file_name}"
mkdir -p "$target_dir"
'' else ''
# Flatten files (copy all to output root)
base_name=$(basename "$proto_file" .proto)
file_name="${base_name}.proto"
if [ -n "${filePrefix}" ]; then
file_name="${filePrefix}${file_name}"
fi
if [ -n "${fileSuffix}" ]; then
file_name="${base_name}${fileSuffix}.proto"
if [ -n "${filePrefix}" ]; then
file_name="${filePrefix}${base_name}${fileSuffix}.proto"
fi
fi
target_file="${outputPath}/${file_name}"

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +81
base_name=$(basename "$rel_path" .proto)
target_file="${outputPath}/$(dirname "$rel_path")/$base_name${fileSuffix}.proto"
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the prefix logic, this suffix logic also overrides the target_file variable, potentially overriding any prefix that was applied. The prefix and suffix transformations should be combined into a single calculation to ensure both are applied correctly.

Copilot uses AI. Check for mistakes.
@connerohnesorge connerohnesorge merged commit 9fe55fc into main Oct 13, 2025
4 checks passed
@connerohnesorge connerohnesorge deleted the copier branch October 13, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants