protobuffctl

About API CLI Guide Architecture Git-Repo

CLI Guide

install globally

>> npm i -g protobuffctl

Check out the commands and their args:

>> protobuffctl 

=>

...
Usage: protobuffctl [options] [command]

Options:
  -h, --help                                              display help for command

Commands:
  startAll                                                Start all watchers
  stopAll                                                 Stop all watchers
  create <type> <arg1> [arg2] [arg3]]                     Initializes a new Proto-object,enum,type,service or ProtobuffFile in the registry
  del <type> <id>                                         Deletes a component, you need to Pull afterwards

...

create a base proto file

>> protobuffctl create proto test.proto ./

this will create a test.proto in your current directory and output:

...
----------- created proto content -----------
syntax="proto3";
option java_multiple_files = true;
option java_package = "./";
option java_outer_classname = "test";
option objc_class_prefix = "HLW";
option go_package = "./";

package test;

add a Type to your Proto:

>> protobuffctl create type HelloRequest

Since we did not pass any fields, the output will look like this:

...
creating HelloRequest
successfully set types HelloRequest
 []

check if it was successfully created:

>> protobuffctl getAll types

without the describe flag at the end, it will output something like this:

...
[ 'HelloRequest']

create a field:

 >> protobuffctl create field message string 

=>

...
successfully set fields message
{ message: { type: 'string', id: -1 } }

create another Type and add our Field to HelloRequest:

>> protobuffctl create type HelloReply message

=>

...
fields
[ 'message' ]
creating HelloReply
successfully set types HelloReply

…adding it to HelloRequest:

>> protobuffctl add field message HelloRequest

create a Method:

>> protobuffctl create method SayHello HelloRequest HelloReply 

=>

... 
{
  SayHello: { requestType: 'HelloRequest', responseType: 'HelloReply' }
}
successfully set methods SayHello
 {"SayHello":{"requestType":"HelloRequest","responseType":"HelloReply"}}

create Service using our Method:

>> protobuffctl create service Greeter SayHello

=>

"methods"
[ 'SayHello' ]
creating Greeter
successfully set services Greeter
 ["SayHello"]

printing all components using GetAll:

>> protobuffctl getAll
...
Map(10) {
  'test_op' => 'options',
  'test' => 'protoFiles',
  'HelloRequest' => 'types',
  'string' => 'fields',
  'message' => 'fields',
  'HelloReply' => 'types',
  'SayHello' => 'methods',
  'Greeter' => 'services'
}

Creating a Protobuff File and Object:

>> protobuffctl create protobuff test ts /your/output_path

this should output something like this if it compiled successfully:

successuflly created protobuff file 🤑🤑🤑 
__________
finished command: ["ts","/your/output_path","test.proto","./",null]

if so you find a test.ts file in /your/output_path. however, since we did not pull changes to the protoFile, we need to update it first. and the output of the protoFile will look like this:

/**
 * Generated by the protoc-gen-ts.  DO NOT EDIT!
 * compiler version: 3.20.3
 * source: test.proto
 * git: https://github.com/thesayyn/protoc-gen-ts */
export namespace test { }

Pull to update the .proto File