reproto - reconstruct .proto source files from compiled protobuf
descriptor sets
reproto [OPTIONS] DESCRIPTOR_FILES...
reproto reads one or more binary or text-format protobuf
descriptor sets and regenerates the original .proto source files with
correct syntax, field types, and options.
It supports proto2, proto3, and editions syntax, and accepts both
.pb (binary FileDescriptorSet) and .textpb
(text-format) descriptor files as input.
- DESCRIPTOR_FILES
- One or more descriptor files to process. Accepts binary
FileDescriptorSet, binary FileDescriptorProto, #@
prototext-format descriptors, or directories (processed recursively). Any
file extension is accepted; .pb and .desc are conventional.
Paths are resolved relative to directories given by -I
(--desc-root), or relative to the current working directory if
-I is not provided.
- -I, --desc-root
DIRECTORY
- Root directory for resolving relative DESCRIPTOR_FILES paths and for
locating imports (repeatable; like protoc -I).
- -O, --proto-out
DIRECTORY
- Output directory for generated .proto files (created if absent). Not
required when using --schema-db-out, --scoring-html-out, or
--dry-run.
- -b,
--emit-binary
- Also write binary descriptor files (.pb) alongside .proto output
- --dry-run
- Do not actually create .proto files
- --proto-variant
FILE
- Path to a variant specification YAML file. If omitted, $REPROTO_VARIANT is
used; otherwise the built-in google.protobuf default applies.
- --use-variant
CHOICE
- Use the variant´s embedded copy of a well-known file instead of
whatever the input .pb files contain. Accepts: any, empty, timestamp,
duration, struct, wrappers, descriptor, all. May be repeated.
- --keep-descriptor-path
- Keep the variant descriptor import path as-is (do not rewrite to
google/protobuf/descriptor.proto)
- --emit-descriptor
- Write descriptor.proto to the output directory (suppressed by
default)
- -s, --seed
TEXT
- FQDN or glob pattern to treat as an output root. Plain FQDN:
desc:my.pkg.MyMsg or file:foo.proto. Glob: file:borg/common/*.proto (one
level), file:borg/** (recursive), desc:my.pkg.* (one level).
- -p, --prune
TEXT
- FQDN or glob pattern to exclude from output. Plain FQDN: desc:my.pkg.MyMsg
or file:foo.proto. Glob: file:borg/common/*.proto (one level),
file:borg/** (recursive), desc:my.pkg.* (one level).
- --force-proto2-output
- Force all output to proto2 syntax, regardless of the input syntax. Without
this flag, output syntax matches the input (polyglot mode).
- --force-proto2-for-editions
- Translate editions-syntax files to proto2 in output and binary
descriptors. Symmetric with --force-proto2-output but limited to editions
files only. --schema-db-out forces this unconditionally.
- --redact-comments
- Redact comments from reconstructed .proto files
- --redact-orphans
- Redact orphans from reconstructed .proto files
- --go-root
TEXT
- Force go_package option in reconstructed .proto files
- --schema-db-out
FILE
- Write the schema DB to FILE (must end in .desc). Writes FILE
(FileDescriptorSet of all loaded FDPs), FILE-stem/hopcroft.rkyv (compiled
scoring graph), and FILE-stem/index.rkyv (lazy-loading FDS index).
- --emit-scoring-yaml
- Write per-file scoring-graph YAML files alongside .proto output under
--proto-out
- --scoring-html-out
FILE
- Write scoring-graph HTML visualisations to FILE; requires
--schema-db-out
- --with-leaf-nodes
- Include leaf (wire-type sink) nodes in --scoring-html-out graphs (hidden
by default)
- --hide
TEXT
- FQDN or glob pattern to hide from --scoring-html-out graphs (same syntax
as --prune). Matched nodes and their incident edges are dropped from the
HTML; no effect on the schema DB.
- --debug
- Print detailed debug information (development only)
- --phase2-plugin
PATH
- Python file executed as a transformation hook during phase 2. Must define
phase2_plugin(ctx, fdp).
- --keep-duplicates
- Do not prune files whose symbols conflict with already-loaded files
(legacy behaviour; by default conflicting files are silently pruned and a
warning is emitted).
- --detailed-warnings
- Print every warning occurrence immediately as it is emitted (default:
squash repeated warnings and show a count summary at the end).
- --quiet,
-q
- Suppress progress messages and warnings. Errors are always printed.
- --debug-fqdn
- Print detailed information about FQDNs (development only)
- --version
- Print version and exit.
- --help
- Show a help message and exit.
- REPROTO_VARIANT
- Path to a variant YAML file used when --proto-variant is not
given.
- _REPROTO_COMPLETE
- When set to bash_complete, emit shell completion candidates and
exit. Used internally by the bash completion script.
reproto does not support multi-file
FileDescriptorSet inputs (i.e. .pb files produced with
protoc --include_imports). Each .pb file must contain exactly
one FileDescriptorProto. Pass all .pb files together on the
command line and let reproto resolve cross-file imports.
Compile each .proto to its own descriptor set (without
--include_imports), then pass all .pb files to reproto:
protoc --descriptor_set_out=phone_number.pb --proto_path=. phone_number.proto
protoc --descriptor_set_out=address_book.pb --proto_path=. address_book.proto
reproto --use-variant descriptor -I . -O out/ phone_number.pb address_book.pb
reproto --use-variant descriptor -I . -O out/ --seed desc:.tutorial.Person \
phone_number.pb address_book.pb
The --use-variant descriptor flag supplies
descriptor.proto from the built-in variant bundle, so no separate
descriptor .pb is needed:
reproto --use-variant descriptor -I . -O out/ phone_number.pb address_book.pb
source <(cat /path/to/reproto/completions.sh)