From ff8231895a66baa5f8e76348d1c5bffc815f83b3 Mon Sep 17 00:00:00 2001 From: Rasmus Viitanen Date: Mon, 5 Aug 2024 13:14:47 +0200 Subject: [PATCH 1/2] Add support for BTreeMap output --- proto-gen/CHANGELOG.md | 3 +++ proto-gen/src/main.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/proto-gen/CHANGELOG.md b/proto-gen/CHANGELOG.md index 86721e7..173b1ce 100644 --- a/proto-gen/CHANGELOG.md +++ b/proto-gen/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Added +- [PR#24](https://github.com/EmbarkStudios/proto-gen/pull/24) Added `--btree-map` option to output BTreeMaps instead of HashMaps. + ## [0.2.6] - 2024-04-25 ### Added - [PR#23](https://github.com/EmbarkStudios/proto-gen/pull/23) Added `--enum-attribute` option to set enum attributes. diff --git a/proto-gen/src/main.rs b/proto-gen/src/main.rs index c87bd3e..94b0bfb 100644 --- a/proto-gen/src/main.rs +++ b/proto-gen/src/main.rs @@ -57,6 +57,10 @@ struct TonicOpts { #[clap(short, long)] disable_comments: Vec, + /// Output maps as `BTreeMap` instead of `HashMap`. Passing '.' makes all maps `BTreeMap`. + #[clap(short, long = "btree-map")] + btree_maps: Vec, + /// Type attributes to add. #[clap(long = "type-attribute", value_parser=KvValueParser)] type_attributes: Vec<(String, String)>, @@ -144,6 +148,8 @@ fn run_with_opts(opts: Opts) -> Result<(), i32> { let mut config = prost_build::Config::new(); config.disable_comments(opts.tonic.disable_comments); + config.btree_map(opts.tonic.btree_maps); + let (ws, commit) = match opts.routine { Routine::Validate { workspace } => (workspace, false), Routine::Generate { workspace } => (workspace, true), @@ -241,6 +247,7 @@ message TestMessage { disable_comments: vec![], type_attributes: vec![], enum_attributes: vec![], + btree_maps: vec![], client_attributes: vec![], server_attributes: vec![], }; @@ -389,6 +396,7 @@ message NestedTransitiveMsg { disable_comments: vec![], type_attributes: vec![], enum_attributes: vec![], + btree_maps: vec![], client_attributes: vec![], server_attributes: vec![], }; From 3d8666ee33e1480f8d2e66986914dc9fef5d4391 Mon Sep 17 00:00:00 2001 From: Rasmus Viitanen Date: Mon, 5 Aug 2024 14:10:09 +0200 Subject: [PATCH 2/2] Fix documentation lint --- proto-gen/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto-gen/src/main.rs b/proto-gen/src/main.rs index 94b0bfb..08cdb9c 100644 --- a/proto-gen/src/main.rs +++ b/proto-gen/src/main.rs @@ -49,7 +49,7 @@ struct TonicOpts { #[clap(short = 'c', long)] build_client: bool, - /// Whether to generate the ::connect and similar functions for tonic. + /// Whether to generate the `::connect` and similar functions for tonic. #[clap(long)] generate_transport: bool,