Skip to content

Commit 79039e7

Browse files
committed
Improve CLI doc
1 parent 8057cbf commit 79039e7

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rsgen-avro"
3-
version = "0.18.0"
3+
version = "0.18.1"
44
authors = ["Romain Leroux <[email protected]>"]
55
edition = "2024"
66
description = "Command line and library for generating Rust types from Avro schemas"

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ Arguments:
2525
<OUTPUT_FILE> The file where Rust types will be written, '-' for stdout
2626
2727
Options:
28-
--fmt Run rustfmt on the resulting <output-file>
29-
--nullable Replace null fields with their default value when deserializing
30-
--precision <P> Precision for f32/f64 default values that aren't round numbers [default: 3]
31-
--union-deser Custom deserialization for apache-avro multi-valued union types
32-
--chrono-dates Use chrono::NaiveDateTime for date/timestamps logical types
33-
--derive-builders Derive builders for generated record structs
34-
--derive-schemas Derive AvroSchema for generated record structs
35-
--extra_derives Append extra derive macros list to the generated record structs
36-
-h, --help Print help
37-
-V, --version Print version
28+
--fmt Run rustfmt on the resulting <output-file>
29+
--nullable Replace null fields with their default value when deserializing
30+
--precision <P> Precision for f32/f64 default values that aren't round numbers [default: 3]
31+
--union-deser Custom deserialization for apache-avro multi-valued union types
32+
--chrono-dates Use chrono::NaiveDateTime for date/timestamps logical types
33+
--derive-builders Derive builders for generated record structs
34+
--impl-schemas <METHOD> Implement AvroSchema for generated record structs [default: None] [possible values: derive, copy-build-schema, none]
35+
--extra-derives <DERIVES> Extract Derives for generated record structs, comma separated, e.g. `std::fmt::Display,std::string::ToString`
36+
-h, --help Print help (see more with '--help')
37+
-V, --version Print version
3838
```
3939

4040
## Library usage

src/generator.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,25 +302,42 @@ impl Default for GeneratorBuilder {
302302
}
303303
}
304304

305-
#[derive(PartialEq, Debug, Clone, Copy)]
305+
#[derive(PartialEq, Debug, Clone, Copy, Default)]
306306
#[cfg_attr(feature = "build-cli", derive(clap::ValueEnum))]
307-
/// How to implement [`AvroSchema`].
307+
/// How to implement [`AvroSchema`][avsc].
308+
///
309+
/// [avsc]: apache_avro::schema::AvroSchema
308310
pub enum ImplementAvroSchema {
309-
/// Use the [`AvroSchema`] derive.
311+
/// Use the [`AvroSchema`][derive] derive.
312+
///
313+
/// This might result in a slightly different schema, as names can have different
314+
/// capitalisation.
310315
///
311-
/// This might result in a slightly different schema, as names can have different capitalisation.
316+
/// [derive]: derive@apache_avro::AvroSchema
312317
Derive,
318+
313319
/// Copy the schema used at build time.
314320
///
315-
/// This will use the [canonical form](Schema::canonical_form) to create an exact (canonical) match.
321+
/// This will use the [canonical form](Schema::canonical_form) to create an exact
322+
/// (canonical) match. Implementations generated by this functionality won't use the
323+
/// [`AvroSchemaComponent`][avsc-compo] implementation of subtypes.
316324
///
317-
/// Implementations generated by this functionality won't use the [`AvroSchemaComponent`] implementation
318-
/// of subtypes.
325+
/// [avsc-compo]: apache_avro::schema::derive::AvroSchemaComponent
319326
CopyBuildSchema,
320-
/// Do not implement or derive [`AvroSchema`].
327+
328+
/// Do not implement or derive [`AvroSchema`][avsc].
329+
///
330+
/// [avsc]: apache_avro::schema::AvroSchema
331+
#[default]
321332
None,
322333
}
323334

335+
impl std::fmt::Display for ImplementAvroSchema {
336+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
337+
write!(f, "{self:?}")
338+
}
339+
}
340+
324341
impl GeneratorBuilder {
325342
/// Creates a new [`GeneratorBuilder`](GeneratorBuilder).
326343
pub fn new() -> GeneratorBuilder {
@@ -364,12 +381,14 @@ impl GeneratorBuilder {
364381
self
365382
}
366383

367-
/// Add an implementation of [`AvroSchema`].
384+
/// Add an implementation of [`AvroSchema`][avsc].
368385
///
369386
/// This implementation can either use a derive or copy the schema used to generate the type.
370387
/// See [`ImplementAvroSchema`] for more information.
371388
///
372389
/// Applies to record structs.
390+
///
391+
/// [avsc]: apache_avro::schema::AvroSchema
373392
pub fn implement_avro_schema(mut self, impl_schemas: ImplementAvroSchema) -> GeneratorBuilder {
374393
self.impl_schemas = impl_schemas;
375394
self

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ struct Args {
4141
#[clap(long)]
4242
pub derive_builders: bool,
4343

44-
/// Derive AvroSchema for generated record structs
45-
#[clap(long)]
44+
/// Implement AvroSchema for generated record structs
45+
#[clap(long, value_name = "METHOD", default_value_t = Default::default())]
4646
pub impl_schemas: ImplementAvroSchema,
4747

4848
/// Extract Derives for generated record structs, comma separated, e.g. `std::fmt::Display,std::string::ToString`
49-
#[clap(long, value_delimiter = ',')]
49+
#[clap(long, value_name = "DERIVES", value_delimiter = ',')]
5050
pub extra_derives: Vec<String>,
5151
}
5252

0 commit comments

Comments
 (0)