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

feat(sea-orm-cli): output log about generated file name. #735

Merged
merged 7 commits into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions sea-orm-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use regex::Regex;
use sea_orm_codegen::{EntityTransformer, OutputFile, WithSerde};
use std::{error::Error, fmt::Display, fs, io::Write, path::Path, process::Command, str::FromStr};
use url::Url;
use tracing_subscriber::{prelude::*, EnvFilter};

pub async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Error>> {
match matches.subcommand() {
Expand All @@ -21,6 +22,17 @@ pub async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dy
.with_max_level(tracing::Level::DEBUG)
.with_test_writer()
.try_init();
} else {
let filter_layer = EnvFilter::try_new("sea_orm_codegen=info").unwrap();
let fmt_layer = tracing_subscriber::fmt::layer()
.with_target(false)
.with_level(false)
.without_time();

tracing_subscriber::registry()
.with(filter_layer)
.with(fmt_layer)
.init()
kyoto7250 marked this conversation as resolved.
Show resolved Hide resolved
}

let max_connections = args
Expand Down
1 change: 1 addition & 0 deletions sea-orm-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ syn = { version = "^1", default-features = false, features = [
quote = "^1"
heck = "^0.3"
proc-macro2 = "^1"
tracing = { version = "0.1", features = ["log"] }

[dev-dependencies]
pretty_assertions = { version = "^0.7" }
9 changes: 8 additions & 1 deletion sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use std::{collections::HashMap, str::FromStr};
use syn::{punctuated::Punctuated, token::Comma};
use tracing::info;

#[derive(Clone, Debug)]
pub struct EntityWriter {
Expand Down Expand Up @@ -94,6 +95,12 @@ impl EntityWriter {
self.entities
.iter()
.map(|entity| {
let entity_file = format!("{}.rs", entity.get_table_name_snake_case());
info!(
"Generating {}",
entity_file
);
billy1624 marked this conversation as resolved.
Show resolved Hide resolved

let mut lines = Vec::new();
Self::write_doc_comment(&mut lines);
let code_blocks = if expanded_format {
Expand All @@ -103,7 +110,7 @@ impl EntityWriter {
};
Self::write(&mut lines, code_blocks);
OutputFile {
name: format!("{}.rs", entity.get_table_name_snake_case()),
name: entity_file,
content: lines.join("\n\n"),
}
})
Expand Down