Implement command line interface
Implements a command line interface for the module abstracting away the use of protoc to under the hood.
Objectives
- An improvement over the current implementation using protoc
- Ability to easily add options to compilation.
- Backwards compatible.
- Programmatic access to compile files.
How to improve current implementation
- Show information on what is currently happening.
- Make it easier to develop betterproto and hook into the plugin.
- Use typer/click for command line implementation and parsing.
- Show helpful messages when something is a protoc SyntaxError etc.
- Make it easier to debug.
Custom options
- Typer can easily add more arguments to the cli without breaking anything.
Backwards compatibility
This is obviously important. I plan to achieve this with an ENV var which will determine whether or not protoc was invoked with the plugin if it wasn't invoked with protoc I would like to display a warning saying that direct invocation of protoc is depreciated and the command they could use in the future.
Programmatic access
I plan to make a few functions accessible using the betterproto API under the name compile_protobufs in the plugin package using https://github.com/Gobot1234/protobuf-parser.
TODO:
- [x] Better error handling.
- [ ] Cleanup.
- [ ] Make this a "well behaved CLI" (with return codes and stdout/stderr separation.
- [x] Testing
% betterproto compile --help
Usage: betterproto compile [OPTIONS] PATHS...
The recommended way to compile your protobuf files.
Arguments:
PATHS... The protobuf files to compile [required]
Options:
-v, --verbose Whether or not to be verbose [default:
False]
-l, --line-length INTEGER The line length to format with [default:
88]
--generate-services / --no-generate-services
Whether or not to generate servicer stubs
[default: True]
--output DIRECTORY The name of the output directory
-h, --help Show this message and exit.
Main entry point for compilation is with betterproto compile this will make it potentially easier to add custom arguments for compilation down the road and makes invocation much simpler as with the old system you would have to run:
protoc --python_betterproto_out=betterproto_out -I betterproto_out.parent files...
Whereas now it is:
betterproto compile files...
grcp support still needs to be tested but I currently can't do that myself.
Small update on this and my parsing library, I can successfully parse file inputs using protoc, unfortunately making a run function doesn't appear to be very feasible ATM, but I'm hopeful I can get this figured out relatively quickly.