Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/1124 #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sea-orm-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub enum GenerateSubcommands {
long,
use_value_delimiter = true,
takes_value = true,
help = "Add extra derive macros to generated model structs (comma separated), ex. `ts_rs::Ts`"
help = "Add extra derive macros to generated model structs (comma separated), ex. `--derives 'ts_rs::Ts'`"
)]
derives: Vec<String>,

Expand All @@ -245,7 +245,7 @@ pub enum GenerateSubcommands {
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)"`"#
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
13 changes: 3 additions & 10 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,20 @@ fn bonus_derive(derives: Vec<String>) -> TokenStream {
derives
.into_iter()
.fold(TokenStream::default(), |derives, derive| {
if !derive.is_empty() {
let tokens: TokenStream = derive.parse().unwrap();
quote! { #derives, #tokens }
} else {
derives
}
let tokens: TokenStream = derive.parse().unwrap();
quote! { #derives, #tokens }
})
}

/// convert attributes argument to token stream
fn bonus_attributes(attributes: Vec<String>) -> TokenStream {
println!("{:?}", attributes);
attributes
.into_iter()
.filter(|attr| !attr.is_empty())
.map(|attr| format!("#[{attr}]"))
.fold(TokenStream::default(), |attributes, attribute| {
let tokens: TokenStream = attribute.parse().unwrap();
quote! {
#attributes
#tokens
#[#tokens]
}
})
}
Expand Down