work
This commit is contained in:
66
src/main.rs
66
src/main.rs
@@ -1,22 +1,72 @@
|
||||
mod generate;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use clap::Parser;
|
||||
use color_eyre::Result;
|
||||
use figment::{
|
||||
providers::{Format, Serialized, Toml},
|
||||
Figment,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DEFAULTS: [&str; 2] = ["prelude.rs", "mod.rs"];
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
struct Config {
|
||||
sea_orm: SeaOrmConfig,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
struct SeaOrmConfig {
|
||||
expanded_format: bool,
|
||||
table: SeaOrmTableConfig,
|
||||
include_hidden_tables: bool,
|
||||
with_serde: bool,
|
||||
serde_skip_deserializing_primary_key: bool,
|
||||
serde_skip_hidden_column: bool,
|
||||
}
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
struct SeaOrmTableConfig {
|
||||
include_hidden: bool,
|
||||
only: Vec<String>,
|
||||
exclude: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
sea_orm: SeaOrmConfig {
|
||||
table: SeaOrmTableConfig {
|
||||
include_hidden: false,
|
||||
only: Vec::new(),
|
||||
exclude: Vec::new(),
|
||||
},
|
||||
expanded_format: false,
|
||||
include_hidden_tables: false,
|
||||
with_serde: false,
|
||||
serde_skip_hidden_column: false,
|
||||
serde_skip_deserializing_primary_key: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
struct Args {
|
||||
data_dir: PathBuf,
|
||||
#[clap(short, long, default_value = "_entities")]
|
||||
entities_folder: String,
|
||||
#[clap(short, long, default_value = "generator.toml")]
|
||||
config: String,
|
||||
#[clap(short, long, env = "DATABASE_URL")]
|
||||
database_url: String,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
tracing_subscriber::fmt::init();
|
||||
let args = Args::parse();
|
||||
tracing::info!(?args.data_dir, ?args.entities_folder, "Generating/Updating models from entities");
|
||||
|
||||
let config: Config = Figment::new()
|
||||
.merge(Serialized::defaults(Config::default()))
|
||||
.merge(Toml::file(&args.config))
|
||||
.extract()?;
|
||||
tracing::info!(?config);
|
||||
tracing::info!(?args);
|
||||
generate::generate(args.database_url).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user