From fa30519f999b73ce3cf688d65a694e20d08ab050 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Wed, 23 Jun 2021 18:38:11 +0800 Subject: [PATCH] sea-orm-cli read config from .env, update command, rename binary to sea-orm-cli --- Cargo.toml | 1 + examples/cli/.env | 2 + examples/cli/Cargo.toml | 9 ++ examples/cli/README.md | 18 ++++ .../src/out => cli/src/entity}/cake.rs | 0 .../out => cli/src/entity}/cake_filling.rs | 0 .../src/out => cli/src/entity}/filling.rs | 0 .../src/out => cli/src/entity}/fruit.rs | 14 +++ .../src/out => cli/src/entity}/mod.rs | 1 + .../src/out => cli/src/entity}/prelude.rs | 1 + examples/cli/src/entity/vendor.rs | 78 ++++++++++++++++ examples/cli/src/main.rs | 3 + examples/codegen/src/entity/cake.rs | 89 ++++++++++++++++++ examples/codegen/src/entity/cake_filling.rs | 90 ++++++++++++++++++ examples/codegen/src/entity/filling.rs | 75 +++++++++++++++ examples/codegen/src/entity/fruit.rs | 92 +++++++++++++++++++ examples/codegen/src/entity/mod.rs | 7 ++ examples/codegen/src/entity/prelude.rs | 7 ++ examples/codegen/src/entity/vendor.rs | 78 ++++++++++++++++ examples/codegen/src/main.rs | 4 +- sea-orm-cli/Cargo.toml | 3 +- sea-orm-cli/src/cli.rs | 12 ++- sea-orm-cli/src/main.rs | 9 +- 23 files changed, 582 insertions(+), 11 deletions(-) create mode 100644 examples/cli/.env create mode 100644 examples/cli/Cargo.toml create mode 100644 examples/cli/README.md rename examples/{codegen/src/out => cli/src/entity}/cake.rs (100%) rename examples/{codegen/src/out => cli/src/entity}/cake_filling.rs (100%) rename examples/{codegen/src/out => cli/src/entity}/filling.rs (100%) rename examples/{codegen/src/out => cli/src/entity}/fruit.rs (79%) rename examples/{codegen/src/out => cli/src/entity}/mod.rs (88%) rename examples/{codegen/src/out => cli/src/entity}/prelude.rs (84%) create mode 100644 examples/cli/src/entity/vendor.rs create mode 100644 examples/cli/src/main.rs create mode 100644 examples/codegen/src/entity/cake.rs create mode 100644 examples/codegen/src/entity/cake_filling.rs create mode 100644 examples/codegen/src/entity/filling.rs create mode 100644 examples/codegen/src/entity/fruit.rs create mode 100644 examples/codegen/src/entity/mod.rs create mode 100644 examples/codegen/src/entity/prelude.rs create mode 100644 examples/codegen/src/entity/vendor.rs diff --git a/Cargo.toml b/Cargo.toml index 43488456..02a11051 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "sea-orm-cli", "examples/sqlx-mysql", "examples/codegen", + "examples/cli", ] [package] diff --git a/examples/cli/.env b/examples/cli/.env new file mode 100644 index 00000000..e08d4810 --- /dev/null +++ b/examples/cli/.env @@ -0,0 +1,2 @@ +DATABASE_URI=mysql://sea:sea@localhost/bakery +DATABASE_SCHEMA=bakery \ No newline at end of file diff --git a/examples/cli/Cargo.toml b/examples/cli/Cargo.toml new file mode 100644 index 00000000..979e847a --- /dev/null +++ b/examples/cli/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "sea-orm-cli-example" +version = "0.1.0" +edition = "2018" +publish = false + +[dependencies] +sea-orm = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls", "debug-print" ] } +strum = { version = "^0.20", features = [ "derive" ] } diff --git a/examples/cli/README.md b/examples/cli/README.md new file mode 100644 index 00000000..1d34c06e --- /dev/null +++ b/examples/cli/README.md @@ -0,0 +1,18 @@ +# SeaORM CLI Example + +Prepare: + +Setup a test database and configure the connection string in `.env`. +Run `bakery.sql` to setup the test table and data. + +Building sea-orm-cli: + +```sh +(cd ../../sea-orm-cli ; cargo build) +``` + +Generating entity: + +```sh +../../target/debug/sea-orm-cli generate entity -o src/entity +``` diff --git a/examples/codegen/src/out/cake.rs b/examples/cli/src/entity/cake.rs similarity index 100% rename from examples/codegen/src/out/cake.rs rename to examples/cli/src/entity/cake.rs diff --git a/examples/codegen/src/out/cake_filling.rs b/examples/cli/src/entity/cake_filling.rs similarity index 100% rename from examples/codegen/src/out/cake_filling.rs rename to examples/cli/src/entity/cake_filling.rs diff --git a/examples/codegen/src/out/filling.rs b/examples/cli/src/entity/filling.rs similarity index 100% rename from examples/codegen/src/out/filling.rs rename to examples/cli/src/entity/filling.rs diff --git a/examples/codegen/src/out/fruit.rs b/examples/cli/src/entity/fruit.rs similarity index 79% rename from examples/codegen/src/out/fruit.rs rename to examples/cli/src/entity/fruit.rs index 6e190749..d3f21bf9 100644 --- a/examples/codegen/src/out/fruit.rs +++ b/examples/cli/src/entity/fruit.rs @@ -39,6 +39,7 @@ impl PrimaryKeyTrait for PrimaryKey { #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation { Cake, + Vendor, } impl ColumnTrait for Column { @@ -59,6 +60,10 @@ impl RelationTrait for Relation { .from(Column::CakeId) .to(super::cake::Column::Id) .into(), + Self::Vendor => Entity::has_many(super::vendor::Entity) + .from(Column::Id) + .to(super::vendor::Column::FruitId) + .into(), } } } @@ -69,10 +74,19 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::Vendor.def() + } +} + impl Model { pub fn find_cake(&self) -> Select { Entity::find_related().belongs_to::(self) } + pub fn find_vendor(&self) -> Select { + Entity::find_related().belongs_to::(self) + } } impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/codegen/src/out/mod.rs b/examples/cli/src/entity/mod.rs similarity index 88% rename from examples/codegen/src/out/mod.rs rename to examples/cli/src/entity/mod.rs index 006f7e80..395d29f9 100644 --- a/examples/codegen/src/out/mod.rs +++ b/examples/cli/src/entity/mod.rs @@ -4,3 +4,4 @@ pub mod cake; pub mod cake_filling; pub mod filling; pub mod fruit; +pub mod vendor; diff --git a/examples/codegen/src/out/prelude.rs b/examples/cli/src/entity/prelude.rs similarity index 84% rename from examples/codegen/src/out/prelude.rs rename to examples/cli/src/entity/prelude.rs index b4c1c94f..b4e85c78 100644 --- a/examples/codegen/src/out/prelude.rs +++ b/examples/cli/src/entity/prelude.rs @@ -4,3 +4,4 @@ pub use super::cake::Entity as Cake; pub use super::cake_filling::Entity as CakeFilling; pub use super::filling::Entity as Filling; pub use super::fruit::Entity as Fruit; +pub use super::vendor::Entity as Vendor; diff --git a/examples/cli/src/entity/vendor.rs b/examples/cli/src/entity/vendor.rs new file mode 100644 index 00000000..9c4ca7dd --- /dev/null +++ b/examples/cli/src/entity/vendor.rs @@ -0,0 +1,78 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "vendor" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub id: i32, + pub name: String, + pub fruit_id: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + Id, + Name, + FruitId, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + Id, +} + +impl PrimaryKeyTrait for PrimaryKey { + fn auto_increment() -> bool { + true + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Fruit, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::Id => ColumnType::Integer.def(), + Self::Name => ColumnType::String(Some(255u32)).def(), + Self::FruitId => ColumnType::Integer.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Fruit => Entity::has_one(super::fruit::Entity) + .from(Column::FruitId) + .to(super::fruit::Column::Id) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Fruit.def() + } +} + +impl Model { + pub fn find_fruit(&self) -> Select { + Entity::find_related().belongs_to::(self) + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/cli/src/main.rs b/examples/cli/src/main.rs new file mode 100644 index 00000000..1a7baf89 --- /dev/null +++ b/examples/cli/src/main.rs @@ -0,0 +1,3 @@ +mod entity; + +fn main() {} diff --git a/examples/codegen/src/entity/cake.rs b/examples/codegen/src/entity/cake.rs new file mode 100644 index 00000000..87ee5f1a --- /dev/null +++ b/examples/codegen/src/entity/cake.rs @@ -0,0 +1,89 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "cake" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub id: i32, + pub name: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + Id, + Name, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + Id, +} + +impl PrimaryKeyTrait for PrimaryKey { + fn auto_increment() -> bool { + true + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + CakeFilling, + Fruit, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::Id => ColumnType::Integer.def(), + Self::Name => ColumnType::String(Some(255u32)).def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::CakeFilling => Entity::has_many(super::cake_filling::Entity) + .from(Column::Id) + .to(super::cake_filling::Column::CakeId) + .into(), + Self::Fruit => Entity::has_many(super::fruit::Entity) + .from(Column::Id) + .to(super::fruit::Column::CakeId) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::CakeFilling.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Fruit.def() + } +} + +impl Model { + pub fn find_cake_filling(&self) -> Select { + Entity::find_related().belongs_to::(self) + } + pub fn find_fruit(&self) -> Select { + Entity::find_related().belongs_to::(self) + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/codegen/src/entity/cake_filling.rs b/examples/codegen/src/entity/cake_filling.rs new file mode 100644 index 00000000..b35279d4 --- /dev/null +++ b/examples/codegen/src/entity/cake_filling.rs @@ -0,0 +1,90 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "cake_filling" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub cake_id: i32, + pub filling_id: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + CakeId, + FillingId, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + CakeId, + FillingId, +} + +impl PrimaryKeyTrait for PrimaryKey { + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Cake, + Filling, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::CakeId => ColumnType::Integer.def(), + Self::FillingId => ColumnType::Integer.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Cake => Entity::has_one(super::cake::Entity) + .from(Column::CakeId) + .to(super::cake::Column::Id) + .into(), + Self::Filling => Entity::has_one(super::filling::Entity) + .from(Column::FillingId) + .to(super::filling::Column::Id) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Cake.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Filling.def() + } +} + +impl Model { + pub fn find_cake(&self) -> Select { + Entity::find_related().belongs_to::(self) + } + pub fn find_filling(&self) -> Select { + Entity::find_related().belongs_to::(self) + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/codegen/src/entity/filling.rs b/examples/codegen/src/entity/filling.rs new file mode 100644 index 00000000..4134652f --- /dev/null +++ b/examples/codegen/src/entity/filling.rs @@ -0,0 +1,75 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "filling" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub id: i32, + pub name: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + Id, + Name, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + Id, +} + +impl PrimaryKeyTrait for PrimaryKey { + fn auto_increment() -> bool { + true + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + CakeFilling, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::Id => ColumnType::Integer.def(), + Self::Name => ColumnType::String(Some(255u32)).def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::CakeFilling => Entity::has_many(super::cake_filling::Entity) + .from(Column::Id) + .to(super::cake_filling::Column::FillingId) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::CakeFilling.def() + } +} + +impl Model { + pub fn find_cake_filling(&self) -> Select { + Entity::find_related().belongs_to::(self) + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/codegen/src/entity/fruit.rs b/examples/codegen/src/entity/fruit.rs new file mode 100644 index 00000000..d3f21bf9 --- /dev/null +++ b/examples/codegen/src/entity/fruit.rs @@ -0,0 +1,92 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "fruit" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub id: i32, + pub name: String, + pub cake_id: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + Id, + Name, + CakeId, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + Id, +} + +impl PrimaryKeyTrait for PrimaryKey { + fn auto_increment() -> bool { + true + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Cake, + Vendor, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::Id => ColumnType::Integer.def(), + Self::Name => ColumnType::String(Some(255u32)).def(), + Self::CakeId => ColumnType::Integer.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Cake => Entity::has_one(super::cake::Entity) + .from(Column::CakeId) + .to(super::cake::Column::Id) + .into(), + Self::Vendor => Entity::has_many(super::vendor::Entity) + .from(Column::Id) + .to(super::vendor::Column::FruitId) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Cake.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Vendor.def() + } +} + +impl Model { + pub fn find_cake(&self) -> Select { + Entity::find_related().belongs_to::(self) + } + pub fn find_vendor(&self) -> Select { + Entity::find_related().belongs_to::(self) + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/codegen/src/entity/mod.rs b/examples/codegen/src/entity/mod.rs new file mode 100644 index 00000000..395d29f9 --- /dev/null +++ b/examples/codegen/src/entity/mod.rs @@ -0,0 +1,7 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 + +pub mod cake; +pub mod cake_filling; +pub mod filling; +pub mod fruit; +pub mod vendor; diff --git a/examples/codegen/src/entity/prelude.rs b/examples/codegen/src/entity/prelude.rs new file mode 100644 index 00000000..b4e85c78 --- /dev/null +++ b/examples/codegen/src/entity/prelude.rs @@ -0,0 +1,7 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 + +pub use super::cake::Entity as Cake; +pub use super::cake_filling::Entity as CakeFilling; +pub use super::filling::Entity as Filling; +pub use super::fruit::Entity as Fruit; +pub use super::vendor::Entity as Vendor; diff --git a/examples/codegen/src/entity/vendor.rs b/examples/codegen/src/entity/vendor.rs new file mode 100644 index 00000000..9c4ca7dd --- /dev/null +++ b/examples/codegen/src/entity/vendor.rs @@ -0,0 +1,78 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "vendor" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub id: i32, + pub name: String, + pub fruit_id: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + Id, + Name, + FruitId, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + Id, +} + +impl PrimaryKeyTrait for PrimaryKey { + fn auto_increment() -> bool { + true + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Fruit, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::Id => ColumnType::Integer.def(), + Self::Name => ColumnType::String(Some(255u32)).def(), + Self::FruitId => ColumnType::Integer.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Fruit => Entity::has_one(super::fruit::Entity) + .from(Column::FruitId) + .to(super::fruit::Column::Id) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Fruit.def() + } +} + +impl Model { + pub fn find_fruit(&self) -> Select { + Entity::find_related().belongs_to::(self) + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/codegen/src/main.rs b/examples/codegen/src/main.rs index dcc034b2..f15463dd 100644 --- a/examples/codegen/src/main.rs +++ b/examples/codegen/src/main.rs @@ -1,4 +1,4 @@ -mod out; +mod entity; use sea_orm_codegen::{EntityGenerator, Error}; @@ -10,7 +10,7 @@ async fn main() -> Result<(), Error> { let _generator = EntityGenerator::discover(uri, schema) .await? .transform()? - .generate("src/out")?; + .generate("src/entity")?; Ok(()) } diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 88a69588..677954f6 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -12,10 +12,11 @@ keywords = [ "orm", "database", "sql", "mysql", "postgres", "sqlite", "cli" ] publish = false [[bin]] -name = "sea-orm" +name = "sea-orm-cli" path = "src/main.rs" [dependencies] clap = { version = "^2.33.3" } +dotenv = { version = "^0.15" } async-std = { version = "^1.9", features = [ "attributes" ] } sea-orm-codegen = { path = "../sea-orm-codegen" } diff --git a/sea-orm-cli/src/cli.rs b/sea-orm-cli/src/cli.rs index 7bedbb90..474dec5f 100644 --- a/sea-orm-cli/src/cli.rs +++ b/sea-orm-cli/src/cli.rs @@ -1,11 +1,11 @@ use clap::{App, AppSettings, Arg, SubCommand}; pub fn build_cli() -> App<'static, 'static> { - let entity_subcommand = SubCommand::with_name("entity") - .about("Entity related commands") + let entity_subcommand = SubCommand::with_name("generate") + .about("Codegen related commands") .setting(AppSettings::VersionlessSubcommands) .subcommand( - SubCommand::with_name("generate") + SubCommand::with_name("entity") .about("Generate entity") .arg( Arg::with_name("DATABASE_URI") @@ -13,7 +13,8 @@ pub fn build_cli() -> App<'static, 'static> { .short("u") .help("Database URI") .takes_value(true) - .required(true), + .required(true) + .env("DATABASE_URI"), ) .arg( Arg::with_name("DATABASE_SCHEMA") @@ -21,7 +22,8 @@ pub fn build_cli() -> App<'static, 'static> { .short("s") .help("Database schema") .takes_value(true) - .required(true), + .required(true) + .env("DATABASE_SCHEMA"), ) .arg( Arg::with_name("OUTPUT_DIR") diff --git a/sea-orm-cli/src/main.rs b/sea-orm-cli/src/main.rs index ad0451ad..0726e17b 100644 --- a/sea-orm-cli/src/main.rs +++ b/sea-orm-cli/src/main.rs @@ -1,4 +1,5 @@ use clap::ArgMatches; +use dotenv::dotenv; use sea_orm_codegen::EntityGenerator; use std::{error::Error, fmt::Display}; @@ -6,19 +7,21 @@ mod cli; #[async_std::main] async fn main() { + dotenv().ok(); + let matches = cli::build_cli().get_matches(); match matches.subcommand() { - ("entity", Some(matches)) => run_entity_command(matches) + ("generate", Some(matches)) => run_generate_command(matches) .await .unwrap_or_else(handle_error), _ => unreachable!("You should never see this message"), } } -async fn run_entity_command(matches: &ArgMatches<'_>) -> Result<(), Box> { +async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box> { match matches.subcommand() { - ("generate", Some(args)) => { + ("entity", Some(args)) => { let uri = args.value_of("DATABASE_URI").unwrap(); let schema = args.value_of("DATABASE_SCHEMA").unwrap(); let output_dir = args.value_of("OUTPUT_DIR").unwrap();