| Crates.io | tonic-clap |
| lib.rs | tonic-clap |
| version | 0.2.5 |
| created_at | 2025-08-24 21:59:07.890522+00 |
| updated_at | 2025-09-18 04:42:07.54219+00 |
| description | gRPC tonic cli generator core implementation. |
| homepage | |
| repository | https://github.com/youyuanwu/tonic-clap |
| max_upload_size | |
| id | 1808820 |
| size | 85,432 |
Auto generate tonic and clap gRPC CLI (commandline) tool from proto definition.
Features:
Option construction relies on bevy-reflect dynamic reflection. Proc macro does not quite work, and prost code gen is much more difficult to write.
This is experimental is only suitable for testing or debugging you app.
Add dependency:
[dependencies]
serde_json = "*"
tonic-clap = "*"
bevy_reflect = "*"
[build-dependencies]
tonic-clap-build = "*"
Add to your build.rs:
let mut builder = tonic_clap_build::configure().with_tonic_server(false);
let proto_file = Path::new("../../protos/helloworld.proto");
let proto_dir = proto_file.parent().unwrap();
builder.compile(&[proto_file], &[proto_dir]).unwrap();
Include generated file in your app:
pub mod helloworld {
tonic::include_proto!("helloworld");
}
Add generated subcommand to your clap:
#[derive(clap::Parser)]
struct Args {
#[command(subcommand)]
command: helloworld::cli::CommandServices,
}
See example: proto generated-cli-app
See the clap help of the example app
cargo run --bin hwgencli -q -- greeter say-hello2 --name hi --help
Usage: hwgencli.exe greeter say-hello2 [OPTIONS]
Options:
--name <NAME> Arg: String
--field1.fname <FNAME> Arg: String
--field1.fcount <FCOUNT> Arg: i32
--field2 <FIELD2> Arg: Vec<String>
--field3 <FIELD3> Arg: i32
-h, --help Print help
This project is licensed under the MIT license.