Skip to content

Commit

Permalink
sea-orm-cli Implement derives & attributes parameters for entity gene…
Browse files Browse the repository at this point in the history
…ration (#1124)

* implement derives & attributes for cli

* fmt and clippy fix

* use comma delimiter for attributes arg

* Update help message use `'` instead of `"` to quote

* Refactoring

* remove unnecessary cloning

Co-authored-by: Billy Chan <[email protected]>
  • Loading branch information
tsar-boomba and billy1624 authored Dec 20, 2022
1 parent 0e3a7c8 commit b62243d
Show file tree
Hide file tree
Showing 15 changed files with 1,063 additions and 98 deletions.
18 changes: 18 additions & 0 deletions sea-orm-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@ pub enum GenerateSubcommands {
help = "Generate index file as `lib.rs` instead of `mod.rs`."
)]
lib: bool,

#[clap(
value_parser,
long,
use_value_delimiter = true,
takes_value = true,
help = "Add extra derive macros to generated model structs (comma separated), ex. `--derives 'ts_rs::Ts'`"
)]
derives: Vec<String>,

#[clap(
value_parser,
long,
use_value_delimiter = true,
takes_value = true,
help = r#"Add extra attributes to generated model struct, no need for `#[]` (comma separated), ex. `--attributes 'serde(rename_all = "camelCase")','ts(export)'`"#
)]
attributes: Vec<String>,
},
}

Expand Down
4 changes: 4 additions & 0 deletions sea-orm-cli/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub async fn run_generate_command(
with_copy_enums,
date_time_crate,
lib,
derives,
attributes,
} => {
if verbose {
let _ = tracing_subscriber::fmt()
Expand Down Expand Up @@ -160,6 +162,8 @@ pub async fn run_generate_command(
let writer_context = EntityWriterContext::new(
expanded_format,
WithSerde::from_str(&with_serde).unwrap(),
derives,
attributes,
with_copy_enums,
date_time_crate.into(),
schema_name,
Expand Down
Loading

0 comments on commit b62243d

Please sign in to comment.