Skip to content

Commit

Permalink
Cont. sea-orm-cli Implement derives & attributes parameters for entit…
Browse files Browse the repository at this point in the history
…y generation (#1321)

* sea-orm-cli Implement derives & attributes parameters for entity generation (#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 <ccw.billy.123@gmail.com>

* [CLI] generate model with extra derives and attributes

* clippy

Co-authored-by: Isaiah Gamble <77396670+tsar-boomba@users.noreply.github.com>
  • Loading branch information
billy1624 and tsar-boomba authored Dec 20, 2022
1 parent 9282ce2 commit 384ac1b
Show file tree
Hide file tree
Showing 15 changed files with 1,123 additions and 79 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 @@ -243,6 +243,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'`"
)]
model_extra_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)'`"#
)]
model_extra_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 @@ -29,6 +29,8 @@ pub async fn run_generate_command(
with_copy_enums,
date_time_crate,
lib,
model_extra_derives,
model_extra_attributes,
} => {
if verbose {
let _ = tracing_subscriber::fmt()
Expand Down Expand Up @@ -168,6 +170,8 @@ pub async fn run_generate_command(
lib,
serde_skip_deserializing_primary_key,
serde_skip_hidden_column,
model_extra_derives,
model_extra_attributes,
);
let output = EntityTransformer::transform(table_stmts)?.generate(&writer_context);

Expand Down
Loading

0 comments on commit 384ac1b

Please sign in to comment.