uber/prototool

Command-line file/directory specification

bufdev opened this issue · 1 comments

Right now, most commands take something along the lines of dirOrProtoFiles... as their first arguments. These commands also have a flag --dir-mode. The possibilities:

  • You can specify multiple files. If this is done, these files will be explicitly used for protoc calls etc.
  • You can specify exactly one directory. If this is done, Prototool goes up until it finds a prototool.yaml file (or uses the current directory if none is found), and then walks starting at this location for all .proto files, and these are used, except for files in the excludes lists in prototool.yaml files.
  • You can specify exactly one file, along with --dir-mode. This has the effect as if you specified the directory of this file (using the logic above), but errors are only printed for that file. This is useful for e.g. Vim integration.

The idea with "directory builds" is that you often need more than just one file to do a protoc call, for example if you have types in other files in the same package that are not referenced by their fully-qualified name, and/or if you need to know what directories to specify with -I to protoc (by default, the directory of the prototool.yaml file is used).

In general practice, directory builds are what you always want to do. File builds were just added for convenience.

There's a proposal to do the following instead:

  • Only one argument is specified. This has the side effect of making the number of arguments to many commands consistent.
  • If a directory is speficied, do directory mode, as usual.
  • If a file is specified, do the equivalent of --dir-mode above.

There are some side effects, for example you need to special-case the format command probably, but we probably want to do this. It's not as trivial as I first realized, and wanted to open this up for discussion before I do it.

I agree with the proposal here - effectively remove the dir-mode flag and update the behavior so that directories are always processed as directories and single files will honor the "Only use this file, but from the context of the directory that contains it." It will reduce the cognitive load of what dir-mode means in the different contexts.

Let's look into this and make sure it, or something similar, happens before 1.0.