restructure
This commit is contained in:
55
src/main.rs
55
src/main.rs
@@ -3,19 +3,13 @@ mod generator;
|
||||
mod templates;
|
||||
|
||||
use clap::Parser;
|
||||
use color_eyre::{eyre::eyre, Report, Result};
|
||||
use color_eyre::{eyre::eyre, Result};
|
||||
use config::Config;
|
||||
use figment::{
|
||||
providers::{Format, Serialized, Yaml},
|
||||
Figment,
|
||||
};
|
||||
use handlebars::Handlebars;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use sea_orm_codegen::{
|
||||
DateTimeCrate as CodegenDateTimeCrate, EntityTransformer, EntityWriterContext, OutputFile,
|
||||
WithPrelude, WithSerde,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::{fs, io::AsyncWriteExt, process::Command};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -25,10 +19,11 @@ struct Args {
|
||||
#[clap(short, long, env = "DATABASE_URL")]
|
||||
database_url: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
tracing_subscriber::fmt::init();
|
||||
tracing_subscriber::fmt().init();
|
||||
let args = Args::parse();
|
||||
|
||||
let config: Config = Figment::new()
|
||||
@@ -52,7 +47,7 @@ async fn main() -> Result<()> {
|
||||
|
||||
let merged_outputs = generator::file::combine_chunks(outputs)?;
|
||||
for output in merged_outputs.iter() {
|
||||
tracing::info!(?output, "Merged file");
|
||||
tracing::info!(?output.path, "Merged file");
|
||||
let parent = output.path.parent().unwrap();
|
||||
if !parent.exists() {
|
||||
fs::create_dir_all(parent).await?;
|
||||
@@ -61,51 +56,11 @@ async fn main() -> Result<()> {
|
||||
file.write_all(output.content.as_bytes()).await?;
|
||||
}
|
||||
for output in merged_outputs.iter() {
|
||||
tracing::info!(?output, "Running rustfmt");
|
||||
tracing::info!(?output.path, "Running rustfmt");
|
||||
let exit_status = Command::new("rustfmt").arg(&output.path).status().await?;
|
||||
if !exit_status.success() {
|
||||
return Err(eyre!("Failed to run rustfmt"));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// let output_dir = &config.output.path;
|
||||
//
|
||||
// let output_models_dir = output_dir.join(&config.output.models.path);
|
||||
//
|
||||
// let output_internal_entities = output_models_dir.join(&config.output.models.entities);
|
||||
// let (_, table_stmts, db_type) =
|
||||
// generator::discover::get_tables(args.database_url, &config).await?;
|
||||
// let writer_context = config.clone().into();
|
||||
// let output = EntityTransformer::transform(table_stmts.clone())?.generate(&writer_context);
|
||||
// let mut files = output
|
||||
// .files
|
||||
// .into_iter()
|
||||
// .map(|OutputFile { name, content }| (output_internal_entities.join(name), content))
|
||||
// .collect::<Vec<_>>();
|
||||
// // generator::update_files(table_stmts, config.clone(), &handlebars).await?;
|
||||
// let generate_files = generator::update_files(table_stmts, config.clone(), &handlebars, db_type)
|
||||
// .await?
|
||||
// .into_iter()
|
||||
// .map(|OutputFile { name, content }| (output_models_dir.join(name), content))
|
||||
// .collect::<Vec<_>>();
|
||||
// files.extend(generate_files);
|
||||
// tracing::info!("Generated {} files", files.len());
|
||||
// fs::create_dir_all(&output_internal_entities).await?;
|
||||
//
|
||||
// for (file_path, content) in files.iter() {
|
||||
// tracing::info!(?file_path, "Writing file");
|
||||
// let mut file = fs::File::create(&file_path).await?;
|
||||
// file.write_all(content.as_bytes()).await?;
|
||||
// }
|
||||
//
|
||||
// for (file_path, ..) in files.iter() {
|
||||
// tracing::info!(?file_path, "Running rustfmt");
|
||||
// let exit_status = Command::new("rustfmt").arg(file_path).status().await?; // Get the status code
|
||||
// if !exit_status.success() {
|
||||
// // Propagate the error if any
|
||||
// return Err(eyre!("Failed to run rustfmt"));
|
||||
// }
|
||||
// }
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user