diff --git a/sea-orm-cli/src/bin/main.rs b/sea-orm-cli/src/bin/main.rs index 3a4e28ac8..96e7c42b1 100644 --- a/sea-orm-cli/src/bin/main.rs +++ b/sea-orm-cli/src/bin/main.rs @@ -1,32 +1,4 @@ -use clap::Parser; -use dotenvy::dotenv; -use sea_orm_cli::{handle_error, run_generate_command, run_migrate_command, Cli, Commands}; - #[async_std::main] async fn main() { - dotenv().ok(); - - let cli = Cli::parse(); - let verbose = cli.verbose; - - match cli.command { - Commands::Generate { command } => { - run_generate_command(command, verbose) - .await - .unwrap_or_else(handle_error); - } - Commands::Migrate { - migration_dir, - database_schema, - database_url, - command, - } => run_migrate_command( - command, - &migration_dir, - database_schema, - database_url, - verbose, - ) - .unwrap_or_else(handle_error), - } + sea_orm_cli::main().await } diff --git a/sea-orm-cli/src/bin/sea.rs b/sea-orm-cli/src/bin/sea.rs index cef653910..f2a1f18e6 100644 --- a/sea-orm-cli/src/bin/sea.rs +++ b/sea-orm-cli/src/bin/sea.rs @@ -1,34 +1,6 @@ //! COPY FROM bin/main.rs -use clap::Parser; -use dotenvy::dotenv; -use sea_orm_cli::{handle_error, run_generate_command, run_migrate_command, Cli, Commands}; - #[async_std::main] async fn main() { - dotenv().ok(); - - let cli = Cli::parse(); - let verbose = cli.verbose; - - match cli.command { - Commands::Generate { command } => { - run_generate_command(command, verbose) - .await - .unwrap_or_else(handle_error); - } - Commands::Migrate { - migration_dir, - database_schema, - database_url, - command, - } => run_migrate_command( - command, - &migration_dir, - database_schema, - database_url, - verbose, - ) - .unwrap_or_else(handle_error), - } + sea_orm_cli::main().await } diff --git a/sea-orm-cli/src/cli.rs b/sea-orm-cli/src/cli.rs index e8611373e..79af1190f 100644 --- a/sea-orm-cli/src/cli.rs +++ b/sea-orm-cli/src/cli.rs @@ -1,4 +1,9 @@ use clap::{ArgGroup, Parser, Subcommand, ValueEnum}; +#[cfg(feature = "codegen")] +use dotenvy::dotenv; + +#[cfg(feature = "codegen")] +use crate::{handle_error, run_generate_command, run_migrate_command}; #[derive(Parser, Debug)] #[command( @@ -309,3 +314,34 @@ pub enum DateTimeCrate { Chrono, Time, } + +/// Use this to build a local, version-controlled `sea-orm-cli` in dependent projects +/// (see [example use case](https://github.com/SeaQL/sea-orm/discussions/1889)). +#[cfg(feature = "codegen")] +pub async fn main() { + dotenv().ok(); + + let cli = Cli::parse(); + let verbose = cli.verbose; + + match cli.command { + Commands::Generate { command } => { + run_generate_command(command, verbose) + .await + .unwrap_or_else(handle_error); + } + Commands::Migrate { + migration_dir, + database_schema, + database_url, + command, + } => run_migrate_command( + command, + &migration_dir, + database_schema, + database_url, + verbose, + ) + .unwrap_or_else(handle_error), + } +}