prototool create creates Protobuf files from a template. With the provided Vim integration, this
will automatically create new files that pass lint when a new file is opened.
Assuming the filename example_create_file.proto, the file will look like the following:
syntax = "proto3";
package some.pkg;
option go_package = "pkgpb";
option java_multiple_files = true;
option java_outer_classname = "ExampleCreateFileProto";
option java_package = "com.some.pkg.pb";If using the uber2 lint group, the file will look like the following:
syntax = "proto3";
package some.pkg.v1;
option csharp_namespace = "Some.Pkg.V1"
option go_package = "pkgv1";
option java_multiple_files = true;
option java_outer_classname = "ExampleCreateFileProto";
option java_package = "com.some.pkg.v1";
option objc_class_prefix = "SPX";
option php_namespace = "Some\\Pkg\\V1";This matches what the linter expects, and closely matches the Google Cloud APIs File Structure.
The package some.pkg will be computed as follows:
- If
--packageis specified,some.pkgwill be the value passed to--package. - Otherwise, if there is no
prototool.yamlorprototool.jsonthat would apply to the new file, useuber.prototool.generated, oruber.prototool.generated.v1if using theuber2lint group. - Otherwise, if there is a
prototool.yamlorprototool.jsonfile, check if it has apackagessetting under thecreatesection (see etc/config/example/prototool.yaml for an example). If it does, this package, concatenated with the relative path from the directory with theprototool.yamlorprototool.jsonfile will be used. - Otherwise, if there is no
packagesdirective, just use the relative path from the directory with theprototool.yamlorprototool.jsonfile. If the file is in the same directory as theprototool.yamlfile, useuber.prototool.generatedoruber.prototool.generated.v1.
For example, assume you have the following file at repo/prototool.yaml:
create:
packages:
- directory: idl
name: uber
- directory: idl/baz
name: specialprototool create repo/idl/foo/bar/bar.protowill have the packageuber.foo.bar.prototool create repo/idl/bar.protowill have the packageuber.prototool create repo/idl/baz/baz.protowill have the packagespecial.prototool create repo/idl/baz/bat/bat.protowill have the packagespecial.bat.prototool create repo/another/dir/bar.protowill have the packageanother.dir.prototool create repo/bar.protowill have the packageuber.prototool.generated.
This is meant to mimic what you generally want - a base package for your idl directory, followed by packages matching the directory structure.
Note you can override the directory that the prototool.yaml or prototool.json file is in as
well. If we update our file at repo/prototool.yaml to this:
create:
packages:
- directory: .
name: foo.barThen prototool create repo/bar.proto will have the package foo.bar, and
prototool create repo/another/dir/bar.proto will have the package foo.bar.another.dir.